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
  • I'm quite close to get it to work. There is something wrong in the end of the code where it should put lookups to MLSU 1123

    My eyes cannot find anything wrong with it but it says "Cannot use parentheses when calling a sub". Maybe some of you with more experience on this can fix it?

    Error:
    DlgInternalEventHandlers.cpp, 529, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    InternalEventHandlers.cpp, 297, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    InternalEventHandlers.cpp, 498, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCMethodCallWithRetry.h, 178, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCMethodCallWithRetry.h, 178, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersAdmin.cpp, 264, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersAdmin.cpp, 105, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersHelper.cpp, 225, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersHelper.cpp, 879, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersHelper.cpp, 879, Cannot use parentheses when calling a Sub (0x80040008)
    RPCEventHandlersHelper.cpp, 947, Cannot use parentheses when calling a Sub (0x80040008)
    VaultDBSessionEvents.cpp, 1295, Cannot use parentheses when calling a Sub (0x80040008)
    VaultDBSessionEvents.cpp, 1670, Cannot use parentheses when calling a Sub (0x80040008)
    VaultScriptSessionTemplates.cpp, 195, Cannot use parentheses when calling a Sub (0x80040008)
    CoActiveScriptSite.cpp, 896, Cannot use parentheses when calling a Sub (0x80040008)
    CoActiveScriptSite.cpp, 745, Cannot use parentheses when calling a Sub (0x80040008)
    BeforeCheckInChanges::Ty?maat multiselectiin, 40, Cannot use parentheses when calling a Sub (0x80040008)
    MErrorHelper.cpp, 2390, Cannot use parentheses when calling a Sub (0x80040008)
    (M-Files 19.1.7279.6)



    option explicit

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

    ' Create a search condition for the object class (Ty?maa=Project).
    Dim oSearchCondition1 : Set oSearchCondition1 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition1.ConditionType = MFConditionTypeEqual
    oSearchCondition1.Expression.SetPropertyValueExpression MFBuiltInPropertyDefClass, MFParentChildBehaviorNone, Nothing
    oSearchCondition1.TypedValue.SetValue MFDataType.MFDatatypeLookup, 3
    oSearchConditions.Add -1, oSearchCondition1

    ' Create a search condition for two dates StartDate
    Dim oSearchCondition2 : Set oSearchCondition2 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition2.ConditionType = MFConditionTypeGreaterThanOrEqual
    oSearchCondition2.Expression.DataPropertyValuePropertyDef = 1036
    oSearchCondition2.TypedValue.SetValue MFDataType.MFDatatypeDate, 1124
    oSearchConditions.Add -1, oSearchCondition2

    ' Create a search condition for two dates - EndDate
    Dim oSearchCondition3 : Set oSearchCondition3 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition3.ConditionType = MFConditionTypeLessThanOrEqual
    oSearchCondition3.Expression.DataPropertyValuePropertyDef = 1050
    oSearchCondition3.TypedValue.SetValue MFDataType.MFDatatypeDate, 1125
    oSearchConditions.Add -1, oSearchCondition3

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

    Dim oLookups
    Dim iCounter
    For iCounter = 1 To oSearchResults.Count
    Dim oResult: Set oResult = oSearchResults.Item(iCounter)
    Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
    oLookup.Type = oResult.ObjVer.Type
    oLookup.Item = oResult.ObjVer.ID
    oLookup.SetLatestVersion
    oLookups.Add(-1, oLookup)
    Next

    'Err.Raise MFScriptCancel, oLookups

    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
Reply
  • I'm quite close to get it to work. There is something wrong in the end of the code where it should put lookups to MLSU 1123

    My eyes cannot find anything wrong with it but it says "Cannot use parentheses when calling a sub". Maybe some of you with more experience on this can fix it?

    Error:
    DlgInternalEventHandlers.cpp, 529, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    InternalEventHandlers.cpp, 297, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    InternalEventHandlers.cpp, 498, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCMethodCallWithRetry.h, 178, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCMethodCallWithRetry.h, 178, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersAdmin.cpp, 264, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersAdmin.cpp, 105, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersHelper.cpp, 225, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersHelper.cpp, 879, VBScript-koodi tapahtumak?sittelij?lle 'Ty?maat multiselectiin' on virheellinen. (0x8004084B)
    RPCEventHandlersHelper.cpp, 879, Cannot use parentheses when calling a Sub (0x80040008)
    RPCEventHandlersHelper.cpp, 947, Cannot use parentheses when calling a Sub (0x80040008)
    VaultDBSessionEvents.cpp, 1295, Cannot use parentheses when calling a Sub (0x80040008)
    VaultDBSessionEvents.cpp, 1670, Cannot use parentheses when calling a Sub (0x80040008)
    VaultScriptSessionTemplates.cpp, 195, Cannot use parentheses when calling a Sub (0x80040008)
    CoActiveScriptSite.cpp, 896, Cannot use parentheses when calling a Sub (0x80040008)
    CoActiveScriptSite.cpp, 745, Cannot use parentheses when calling a Sub (0x80040008)
    BeforeCheckInChanges::Ty?maat multiselectiin, 40, Cannot use parentheses when calling a Sub (0x80040008)
    MErrorHelper.cpp, 2390, Cannot use parentheses when calling a Sub (0x80040008)
    (M-Files 19.1.7279.6)



    option explicit

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

    ' Create a search condition for the object class (Ty?maa=Project).
    Dim oSearchCondition1 : Set oSearchCondition1 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition1.ConditionType = MFConditionTypeEqual
    oSearchCondition1.Expression.SetPropertyValueExpression MFBuiltInPropertyDefClass, MFParentChildBehaviorNone, Nothing
    oSearchCondition1.TypedValue.SetValue MFDataType.MFDatatypeLookup, 3
    oSearchConditions.Add -1, oSearchCondition1

    ' Create a search condition for two dates StartDate
    Dim oSearchCondition2 : Set oSearchCondition2 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition2.ConditionType = MFConditionTypeGreaterThanOrEqual
    oSearchCondition2.Expression.DataPropertyValuePropertyDef = 1036
    oSearchCondition2.TypedValue.SetValue MFDataType.MFDatatypeDate, 1124
    oSearchConditions.Add -1, oSearchCondition2

    ' Create a search condition for two dates - EndDate
    Dim oSearchCondition3 : Set oSearchCondition3 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition3.ConditionType = MFConditionTypeLessThanOrEqual
    oSearchCondition3.Expression.DataPropertyValuePropertyDef = 1050
    oSearchCondition3.TypedValue.SetValue MFDataType.MFDatatypeDate, 1125
    oSearchConditions.Add -1, oSearchCondition3

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

    Dim oLookups
    Dim iCounter
    For iCounter = 1 To oSearchResults.Count
    Dim oResult: Set oResult = oSearchResults.Item(iCounter)
    Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
    oLookup.Type = oResult.ObjVer.Type
    oLookup.Item = oResult.ObjVer.ID
    oLookup.SetLatestVersion
    oLookups.Add(-1, oLookup)
    Next

    'Err.Raise MFScriptCancel, oLookups

    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
Children
No Data