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

Merge values from multiple 'Choose from list' properties

Hi, I have a 'Project' object which gets tagged with several mutli-select user lists: Project User, Project Approver etc

I want to get a single combined list of their Organisations, to illustrate which companies are on the project. Ideally with Compliance Kit config rather than VBscript

I can create a Managed Property rule which will return the multi-select list of orgs from 'Project User.Organisation', but if I add another rule for 'Project Approver.Organisation' they will overwrite each other

So, I need to somehow merge all the project team into a single combined list and then get 'Combined Users.Organisation',... or I need to get the various user types' organisations individually and then merge them

How can I merge values from several multi-select properties into a single multi-select property? 
Many thanks

Parents Reply Children
  • Here's what I ended up with

    ' H.EventHandler.MergeContactLists 
    ' Merge separate Contact lists into one combined list
    
    ' Filter by Object Type = Workflow
    Dim iWorkflow : iWorkflow = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("H.Object.Workflow")
    If ObjVer.Type = iWorkflow Then 
    	
    	' Filter by Class = Make Confidential
        Dim iClassId
        iClassId = Vault.ClassOperations.GetObjectClassIDByAlias("H.Class.MakeConfidential")
    	Dim oPropVal : Set oPropVal = CreateObject("MFilesApi.PropertyValues")
    	Set oPropVal = Vault.ObjectPropertyOperations.GetProperties(ObjVer)	
    	If oPropVal.SearchForProperty(MFBuiltInPropertyDefClass).TypedValue.GetValueAsLookup.Item = iClassId Then 
    
    '''''''''' Get the Users tagged on the Workflow in different properties
    		' Property 1 - 'Named Project Users' - this is the first source that will be read from
    		Dim oProp1Alias : oProp1Alias = "H.Property.NamedProjectUsers"
    		Dim oLookup1 : Set oLookup1 = CreateObject("MFilesAPI.Lookup")
    		Dim oLookups1 : Set oLookups1 = oPropVal.SearchForPropertyByAlias(Vault, oProp1Alias, True).TypedValue.GetValueAsLookups
    
            ' Property 2 - 'Named Project Approver' - this is an additional source that will be read from
    		Dim oProp2Alias : oProp2Alias = "H.Property.NamedProjectApprover"
    		Dim oLookup2 : Set oLookup2 = CreateObject("MFilesAPI.Lookup")
    		Dim oLookups2 : Set oLookups2 = oPropVal.SearchForPropertyByAlias(Vault, oProp2Alias, True).TypedValue.GetValueAsLookups
    		
    		' Property 3 - 'Named Task Team Users' - this is an additional source that will be read from
    		Dim oProp3Alias : oProp3Alias = "H.Property.NamedTaskTeamUsers"
    		Dim oLookup3 : Set oLookup3 = CreateObject("MFilesAPI.Lookup")
    		Dim oLookups3 : Set oLookups3 = oPropVal.SearchForPropertyByAlias(Vault, oProp3Alias, True).TypedValue.GetValueAsLookups
    
    		' Property 4 - 'Named Project Task Team Approver' - this is an additional source that will be read from
    		Dim oProp4Alias : oProp4Alias = "H.Property.NamedProjectTaskTeamApprover"
    		Dim oLookup4 : Set oLookup4 = CreateObject("MFilesAPI.Lookup")
    		Dim oLookups4 : Set oLookups4 = oPropVal.SearchForPropertyByAlias(Vault, oProp4Alias, True).TypedValue.GetValueAsLookups
    
    		' Property 5 - 'Named Users' - this is an additional source that will be read from
    		Dim oProp5Alias : oProp5Alias = "H.Property.NamedUsers"
    		Dim oLookup5 : Set oLookup5 = CreateObject("MFilesAPI.Lookup")
    		Dim oLookups5 : Set oLookups5 = oPropVal.SearchForPropertyByAlias(Vault, oProp5Alias, True).TypedValue.GetValueAsLookups
    		
    '''''''''' Combine the different properties into a single list
    		' Create a temporary list starting with 'Named Project Users'
    		Dim oDictionary : Set oDictionary = CreateObject("Scripting.Dictionary")
    		For Each oLookup1 In oLookups1
    		    Call oDictionary.Add(oLookup1.DisplayValue, 0)
    		Next
    		
    		' If the 'Named Project Approver' does not already exist in the temporary list, add it to oLookups1 & update the temp list
    		For Each oLookup2 In oLookups2
    			If Not oDictionary.Exists(oLookup2.DisplayValue) Then 
    				oLookups1.Add -1, oLookup2
    				Call oDictionary.Add(oLookup2.DisplayValue, 0)
    			End If
    		Next
    
    		' If the 'Named Task Team Users' does not already exist in the temporary list, add it to oLookups1 & update the temp list
    		For Each oLookup3 In oLookups3
    			If Not oDictionary.Exists(oLookup3.DisplayValue) Then 
    				oLookups1.Add -1, oLookup3
    				Call oDictionary.Add(oLookup3.DisplayValue, 0)
    			End If
    		Next
    
    		' If the 'Named Project Task Team Approver' does not already exist in the temporary list, add it to oLookups1 
    		For Each oLookup4 In oLookups4
    			If Not oDictionary.Exists(oLookup4.DisplayValue) Then 
    				oLookups1.Add -1, oLookup4
    				Call oDictionary.Add(oLookup4.DisplayValue, 0)
    			End If
    		Next
    
    		' If the 'Named Users' does not already exist in the temporary list, add it to oLookups1 
    		For Each oLookup5 In oLookups5
    			If Not oDictionary.Exists(oLookup5.DisplayValue) Then 
    				oLookups1.Add -1, oLookup5
    			End If
    		Next
    
    '''''''''' Write the combined list back to the object
    		' Property CU - Existing list of Combined Users - this is the destination that will be written to
    		Dim oPropCUAlias : oPropCUAlias = "H.Property.CombinedUsers"
    		Dim oLookupCU : Set oLookupCU = CreateObject("MFilesAPI.Lookup")
    		Dim oLookupsCU : Set oLookupsCU = oPropVal.SearchForPropertyByAlias(Vault, oPropCUAlias, True).TypedValue.GetValueAsLookups
    		
    		' Save the combined list back to the Workflow object
    		Dim oPropertyValue : Set oPropertyValue = CreateObject("MFilesAPI.PropertyValue")
    		oPropertyValue.TypedValue.SetValueToMultiSelectLookup(oLookups1)
    		oPropertyValue.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias(oPropCUAlias)
    		
    		Call Vault.ObjectPropertyOperations.SetProperty(ObjVer, oPropertyValue)
    
    	End If ' End check for Class
    
    End If ' End check for Object type