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

Select multiple values in a multi-select property. Files Source OR Workflow

I need to automatically select 2 (or more) values in a multi-select on a file source import. It appears only 1 can be set. So I figured I would use a workflow instead. It appears the same limitation is present in the workflow "Set Properties" option of only being able to select 1 value. How can this be done? Will this functionality be added to the product soon?
Parents
  • Well, I can't share the 300+ lines in full because they are highly customized to a specific customer and a quite complex setup. However, the principles are:
    1 Create a list to the hold lookup items needed for output
    2 Search for the relevant items and add them to the list. Use Scripting Dictionary to make sure you only get the same item once if you need multiple searches to find all the relevant item. If you need to pull values from automated properties, then you need to make sure they have been updated prior to using the values.
    3 Manipulate each item to lock down a specific version if needed.
    4 Use the list as output from your script.
    (Code has been edited here for simplicity, forgive me for any mistakes - have not tested this version)

    Dim oList: set oList = CreateObject("MFilesAPI.Lookups")
    Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
    dim oNewLookup: Set oNewLookup = CreateObject("MFilesAPI.Lookup")
    oNewLookup.ObjectType = 0
    Dim oDic : Set oDic = CreateObject("Scripting.Dictionary")
    ' create one or more searches to find the objects that you want to add to you property.
    ' values could also be fetched from a multiselect property on the same or a related object if relevant.
    ' if more than one search is required you need to make sure that the same result is not entered twice. Hence the use of a scripting dictionary. This is not needed in a single search configuration.
    'Create a new list for each search, use TypedValue.GetValueAsLookups() on the search results.
    'For each new list you need to check whether each item is already in the scripting dictionary, if not than add it to the final list.
    'Sample code for objects found in a multiselect property (will add a specific version of the objects to the list):
    Dim oList, oList1, oList2
    set oList1 = oPropVals.SearchForProperty(iYourPropertyID).TypedValue.GetValueAsLookups()
    If oList1.Count > 0 then
    For each oLookup in oList1
    oNewLookup.Item = oLookup.Item
    oNewLookup.Version = oLookup.Version
    If not oDic.Exists(oLookup.Item) then
    oDic.Add oLookup.Item, oLookup.Version
    OList.Add -1, oNewLookup
    End if
    Next
    End if
    ' sample code for objects found in a search
    Dim oOneSC: Set oOneSC = CreateObject("MFilesAPI.SearchCondition")
    Dim oSCs: Set oSCs = CreateObject("MFilesAPI.SearchConditions")
    ' Deleted = no
    oOneSC.ConditionType = MFConditionTypeEqual
    oOneSC.Expression.DataStatusValueType = MFStatusTypeDeleted
    oOneSC.TypedValue.SetValue MFDatatypeBoolean, False
    oSCs.Add -1, oOneSC
    ' Object type = X
    oOneSC.ConditionType = MFConditionTypeEqual
    oOneSC.Expression.DataStatusValueType = MFStatusTypeObjectTypeID
    oOneSC.TypedValue.SetValue MFDatatypeLookup, iOTX
    oScs.Add -1, oOneSC'
    'add other relevant search criteria
    Dim oSearchResult, oSearchResults
    Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oScs, MFSearchFlagNone, False)
    'In my case I need to retrieve objects from a multiselect property on the objects found by the above search.
    'This property is automatically updated via Compliance Kit, Managed Properties, therefor I have to make sure it is updated before I use the results.
    If oSearchResults.count > 0 then
    Dim oXObjID, szBuildVar, oObjectVersionAndProperties, oAObjVer, oBObjVer, oBVersionX, oBProp, oBProps, oPropVals, oADocs, thisProperty
    For each oSearchResult in oSearchResults
    ' Update the managed properties for the object where necessary
    set oObjectVersionAndProperties = vault.ObjectOperations.GetObjectVersionAndProperties(oSearchResult.ObjVer, True)
    set oXObjID = oSearchResult.ObjVer.ObjID
    if not oObjectVersionAndProperties.VersionData.ObjectCheckedOut then
    szBuildVar = "["& Chr(34) & "UpdateAutomaticProperties" & Chr(34) &", " & Chr(34) & "(" & CStr( oXObjID.Type ) & "-" & CStr( oXObjID.ID ) & ")" & Chr(34) & "]"
    Vault.ExtensionMethodOperations.ExecuteVaultExtensionMethod "MFiles.ComplianceKit.MFEventHandlerVaultExtensionMethod", szBuildVar
    end if
    'Get referenced documents from the updated objects and change link to fixed version.
    Set oAObjVer = Vault.ObjectOperations.GetLatestObjVer(oXObjID,False,True)
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties( oAObjVer, True )
    Set oADocs = oPropVals.SearchForProperty(iPDRefdByDocs).TypedValue.GetValueAsLookups()
    if Not oADocs.count = 0 then
    For Each oADoc In oADocs
    if not oAdoc.Deleted = True then
    ' Set to current version instead of -1, then add to list for further processing
    oObjID.SetIDs 0, oADoc.Item '0 = object type Document
    Set oBObjVer = Vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
    oBVersionX = oBObjver.VersionEx.Version
    oBProp.Item = oADoc.Item
    oBProp.Version = oBVersionX
    oBProps.Add -1, oBProp
    End if
    Next
    'Set the found values to the list
    thisProperty.TypedValue.SetValueToMultiSelectLookup oBProps
    set oList2 = thisProperty.TypedValue.GetValueAsLookups()
    If oList2.Count > 0 then
    For each oLookup in oList2
    oNewLookup.Item = oLookup.Item
    oNewLookup.Version = oLookup.Version
    If not oDic.Exists(oLookup.Item) then
    oDic.Add oLookup.Item, oLookup.Version
    OList.Add -1, oNewLookup
    End if
    Next
    End if
    end if
    Next
    Output = oList
Reply
  • Well, I can't share the 300+ lines in full because they are highly customized to a specific customer and a quite complex setup. However, the principles are:
    1 Create a list to the hold lookup items needed for output
    2 Search for the relevant items and add them to the list. Use Scripting Dictionary to make sure you only get the same item once if you need multiple searches to find all the relevant item. If you need to pull values from automated properties, then you need to make sure they have been updated prior to using the values.
    3 Manipulate each item to lock down a specific version if needed.
    4 Use the list as output from your script.
    (Code has been edited here for simplicity, forgive me for any mistakes - have not tested this version)

    Dim oList: set oList = CreateObject("MFilesAPI.Lookups")
    Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
    dim oNewLookup: Set oNewLookup = CreateObject("MFilesAPI.Lookup")
    oNewLookup.ObjectType = 0
    Dim oDic : Set oDic = CreateObject("Scripting.Dictionary")
    ' create one or more searches to find the objects that you want to add to you property.
    ' values could also be fetched from a multiselect property on the same or a related object if relevant.
    ' if more than one search is required you need to make sure that the same result is not entered twice. Hence the use of a scripting dictionary. This is not needed in a single search configuration.
    'Create a new list for each search, use TypedValue.GetValueAsLookups() on the search results.
    'For each new list you need to check whether each item is already in the scripting dictionary, if not than add it to the final list.
    'Sample code for objects found in a multiselect property (will add a specific version of the objects to the list):
    Dim oList, oList1, oList2
    set oList1 = oPropVals.SearchForProperty(iYourPropertyID).TypedValue.GetValueAsLookups()
    If oList1.Count > 0 then
    For each oLookup in oList1
    oNewLookup.Item = oLookup.Item
    oNewLookup.Version = oLookup.Version
    If not oDic.Exists(oLookup.Item) then
    oDic.Add oLookup.Item, oLookup.Version
    OList.Add -1, oNewLookup
    End if
    Next
    End if
    ' sample code for objects found in a search
    Dim oOneSC: Set oOneSC = CreateObject("MFilesAPI.SearchCondition")
    Dim oSCs: Set oSCs = CreateObject("MFilesAPI.SearchConditions")
    ' Deleted = no
    oOneSC.ConditionType = MFConditionTypeEqual
    oOneSC.Expression.DataStatusValueType = MFStatusTypeDeleted
    oOneSC.TypedValue.SetValue MFDatatypeBoolean, False
    oSCs.Add -1, oOneSC
    ' Object type = X
    oOneSC.ConditionType = MFConditionTypeEqual
    oOneSC.Expression.DataStatusValueType = MFStatusTypeObjectTypeID
    oOneSC.TypedValue.SetValue MFDatatypeLookup, iOTX
    oScs.Add -1, oOneSC'
    'add other relevant search criteria
    Dim oSearchResult, oSearchResults
    Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oScs, MFSearchFlagNone, False)
    'In my case I need to retrieve objects from a multiselect property on the objects found by the above search.
    'This property is automatically updated via Compliance Kit, Managed Properties, therefor I have to make sure it is updated before I use the results.
    If oSearchResults.count > 0 then
    Dim oXObjID, szBuildVar, oObjectVersionAndProperties, oAObjVer, oBObjVer, oBVersionX, oBProp, oBProps, oPropVals, oADocs, thisProperty
    For each oSearchResult in oSearchResults
    ' Update the managed properties for the object where necessary
    set oObjectVersionAndProperties = vault.ObjectOperations.GetObjectVersionAndProperties(oSearchResult.ObjVer, True)
    set oXObjID = oSearchResult.ObjVer.ObjID
    if not oObjectVersionAndProperties.VersionData.ObjectCheckedOut then
    szBuildVar = "["& Chr(34) & "UpdateAutomaticProperties" & Chr(34) &", " & Chr(34) & "(" & CStr( oXObjID.Type ) & "-" & CStr( oXObjID.ID ) & ")" & Chr(34) & "]"
    Vault.ExtensionMethodOperations.ExecuteVaultExtensionMethod "MFiles.ComplianceKit.MFEventHandlerVaultExtensionMethod", szBuildVar
    end if
    'Get referenced documents from the updated objects and change link to fixed version.
    Set oAObjVer = Vault.ObjectOperations.GetLatestObjVer(oXObjID,False,True)
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties( oAObjVer, True )
    Set oADocs = oPropVals.SearchForProperty(iPDRefdByDocs).TypedValue.GetValueAsLookups()
    if Not oADocs.count = 0 then
    For Each oADoc In oADocs
    if not oAdoc.Deleted = True then
    ' Set to current version instead of -1, then add to list for further processing
    oObjID.SetIDs 0, oADoc.Item '0 = object type Document
    Set oBObjVer = Vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
    oBVersionX = oBObjver.VersionEx.Version
    oBProp.Item = oADoc.Item
    oBProp.Version = oBVersionX
    oBProps.Add -1, oBProp
    End if
    Next
    'Set the found values to the list
    thisProperty.TypedValue.SetValueToMultiSelectLookup oBProps
    set oList2 = thisProperty.TypedValue.GetValueAsLookups()
    If oList2.Count > 0 then
    For each oLookup in oList2
    oNewLookup.Item = oLookup.Item
    oNewLookup.Version = oLookup.Version
    If not oDic.Exists(oLookup.Item) then
    oDic.Add oLookup.Item, oLookup.Version
    OList.Add -1, oNewLookup
    End if
    Next
    End if
    end if
    Next
    Output = oList
Children
No Data