The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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?

  • Perhaps

    vault.ValueListItemOperations.SearchForValueListItemsEx(ValueList,oScs,false,MFExternalDBRefreshTypeNone,true)

  • 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.

  • 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. :