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 Reply Children
  • Thank you biright-ideas.dk for you suggestion, but the script error happens above that line

    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

    at line 6. I've tried your suggestion but it still returns an error at line 6

    this script is an attempt of a translation to vbscript from these examples:
    https://developer.m-files.com/APIs/COM-API/Searching/ValueListItems/
    so I might have it all very wrong here.

    A working vbscript example would be very appreciated, if anyone has one.
    The goal is to retriev the parent ID of a sub list value.