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

Searching for the parent of a value list item

Hello community,

I'm trying to find the parent of a value list item using VBScript.

Dim SearchForValue: SearchForValue = "Apple"
                    
 Dim oSc : Set oSc = CreateObject("MFilesAPI.SearchCondition")
Dim oScs : Set oScs = CreateObject("MFilesAPI.SearchConditions")
oSc.ConditionType = MFConditionType.MFConditionTypeStartsWith
oSc.Expression.SetValueListItemExpression MFValueListItemPropertyDef.MFValueListItemPropertyDefName, MFParentChildBehavior.MFParentChildBehaviorNone
oSc.TypedValue.SetValue MFDataType.MFDatatypeText, SearchForValue
oScs.Add -1, oSc

Dim ValueList: ValueList = 125 ' the ID of the value list for fruits

'Perform search.
Dim oRes
Dim oResults : Set oResults = vault.ValueListItemOperations.SearchForValueListItemsEx(ValueList,oScs,false,MFExternalDBRefreshType.MFExternalDBRefreshTypeNone,true)

'Result:
If oResults.Count = 1 Then ' Only try to write if there is one result
                        Dim IDOfResult, IDOfParent
                        Set oRes = oResults.Item(1)
                        IDOfResult = oRes.ObjVer.ID
                        IDOfParent = oRes.ObjVer.ParentID
End If

I'm getting a Type mismatch error: 'Expression.SetValueListItemExpression', I'm not even getting to the 'IDOfParent = oRes.ObjVer.ParentID' part.

What am I doing wrong?

Parents
  • I have found the issue in my script and a way to get the value list's 'parent' ID:

    Dim SearchForValue: SearchForValue = "Apple"
                        
     Dim oSc : Set oSc = CreateObject("MFilesAPI.SearchCondition")
    Dim oScs : Set oScs = CreateObject("MFilesAPI.SearchConditions")
    oSc.ConditionType = MFConditionType.MFConditionTypeStartsWith
    oSc.Expression.SetValueListItemExpression MFValueListItemPropertyDef.MFValueListItemPropertyDefName, MFParentChildBehavior.MFParentChildBehaviorNone, Nothing
    oSc.TypedValue.SetValue MFDataType.MFDatatypeText, SearchForValue
    oScs.Add -1, oSc
    
    Dim ValueList: ValueList = 125 ' the ID of the value list for fruits
    
    'Perform search.
    Dim oRes
    Dim oResults : Set oResults = vault.ValueListItemOperations.SearchForValueListItemsEx(ValueList,oScs,false,MFExternalDBRefreshType.MFExternalDBRefreshTypeNone,true)
    
    'Result:
    If oResults.Count = 1 Then ' Only try to write if there is one result
                            Dim IDOfResult, IDOfOwner
                            Set oRes = oResults.Item(1)
                            IDOfResult = oRes.ID
                            IDOfOwner = oRes.OwnerID
    End If

    • At line 6 added: "Nothing". That was the source of the Type Mismatch error. *
    • The value list's 'parent' is named Owner and was found using "oRes.OwnerID"

    *by the way, see https://www.m-files.com/api/documentation/#MFilesAPI~Expression~SetValueListItemExpression.html where

    SetValueListItemExpression

    is described to have an optional 'DataFunctionCall'. But hovering over it pops up an explanation that tells to actually use 'nothing' in vbscript. :

Reply
  • I have found the issue in my script and a way to get the value list's 'parent' ID:

    Dim SearchForValue: SearchForValue = "Apple"
                        
     Dim oSc : Set oSc = CreateObject("MFilesAPI.SearchCondition")
    Dim oScs : Set oScs = CreateObject("MFilesAPI.SearchConditions")
    oSc.ConditionType = MFConditionType.MFConditionTypeStartsWith
    oSc.Expression.SetValueListItemExpression MFValueListItemPropertyDef.MFValueListItemPropertyDefName, MFParentChildBehavior.MFParentChildBehaviorNone, Nothing
    oSc.TypedValue.SetValue MFDataType.MFDatatypeText, SearchForValue
    oScs.Add -1, oSc
    
    Dim ValueList: ValueList = 125 ' the ID of the value list for fruits
    
    'Perform search.
    Dim oRes
    Dim oResults : Set oResults = vault.ValueListItemOperations.SearchForValueListItemsEx(ValueList,oScs,false,MFExternalDBRefreshType.MFExternalDBRefreshTypeNone,true)
    
    'Result:
    If oResults.Count = 1 Then ' Only try to write if there is one result
                            Dim IDOfResult, IDOfOwner
                            Set oRes = oResults.Item(1)
                            IDOfResult = oRes.ID
                            IDOfOwner = oRes.OwnerID
    End If

    • At line 6 added: "Nothing". That was the source of the Type Mismatch error. *
    • The value list's 'parent' is named Owner and was found using "oRes.OwnerID"

    *by the way, see https://www.m-files.com/api/documentation/#MFilesAPI~Expression~SetValueListItemExpression.html where

    SetValueListItemExpression

    is described to have an optional 'DataFunctionCall'. But hovering over it pops up an explanation that tells to actually use 'nothing' in vbscript. :

Children
No Data