This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Conditions don't work

Hi,

I'm working on my first "real" M-Files code and first time with conditions. I get type mismatch and that stuff.
What I am trying to achive is: "User sets start and end date that are used to search Projects those dates fit between those user specified dates. Results should be put into MLSU. Search result to MLSU is still to be figured out. I can put one element to MLSU with code there is. So this will be sort of template where user can flip date ranges - Poor mans Gantt on Excel.


option explicit

' Initialize an array of search conditions.
Dim oSearchConditions : Set oSearchConditions = CreateObject("MFilesAPI.SearchConditions")
Dim oSearchCondition1 : Set oSearchCondition1 = CreateObject("MFilesAPI.SearchCondition")
Dim oSearchCondition2 : Set oSearchCondition2 = CreateObject("MFilesAPI.SearchCondition")
Dim oSearchCondition3 : Set oSearchCondition3 = CreateObject("MFilesAPI.SearchCondition")

' Create a search condition for the object class (Ty?maa=Project).
oSearchCondition1.ConditionType = MFConditionTypeEqual
oSearchCondition1.Expression.SetPropertyValueExpression(1026, MFParentChildBehavior.MFParentChildBehaviorNone)
oSearchCondition1.TypedValue.SetValue MFDataType.MFDatatypeLookup, 105
oSearchConditions.Add -1, oSearchCondition1

' Create a search condition for two dates
oSearchCondition1.ConditionType = MFConditionTypeGreaterThanOrEqual
oSearchCondition1.Expression.SetPropertyValueExpression(1124)
oSearchCondition1.TypedValue.SetValue MFDataType.MFDatatypeDate, 1036
oSearchConditions.Add -1, oSearchCondition2

' Create a search condition for two dates
oSearchCondition1.ConditionType = MFConditionTypeLessThanOrEqual
oSearchCondition1.Expression.SetPropertyValueExpression(1125)
oSearchCondition1.TypedValue.SetValue MFDataType.MFDatatypeDate, 1050
oSearchConditions.Add -1, oSearchCondition3

' Execute the search.
Dim oSearchResult
Dim oSearchResults
Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchConditions, MFSearchFlagNone, False)

'Err.Raise MFScriptCancel, oSearchCondition1

Dim oPropertyValue: Set oPropertyValue = CreateObject("MFilesAPI.PropertyValue")
Dim oPropertyValues: Set oPropertyValues = CreateObject("MFilesAPI.PropertyValues")

Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
Dim oLookups: Set oLookups = CreateObject("MFilesAPI.Lookups")

oLookup.Item = 2
oLookup.Version = -1
oLookups.Add -1, oLookup

oPropertyValue.PropertyDef = 1123
oPropertyValue.TypedValue.SetValueToMultiSelectLookup oLookups
oPropertyValues.Add -1, oPropertyValue

Vault.ObjectPropertyOperations.SetProperties ObjVer, oPropertyValues


Thanks

PJ
Parents Reply Children
No Data