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

VBScript: Populate a MultiSelect Property (Text List) from another Multi Select Property (Object List)

I read a lot of threads with similar problems but I think no one asked about this case?

The script should run as a Auto Calculated Value on the Multi Select Property which is based on a Text List.. Can you get me started?

Parents
  • Got it working, here's the code Slight smile

    Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    Dim oLookups1 : Set oLookups1 = PropertyValues.SearchForPropertyByAlias(Vault, "PD.ZugehoerigeObjekte", True).TypedValue.GetValueAsLookups
    Dim oLookup1 : Set oLookup1 = CreateObject("MFilesAPI.Lookup")
    Dim oLookups2 : Set oLookups2 = CreateObject("MFilesAPI.Lookups")
    Dim oLookup2 : Set oLookup2 = CreateObject("MFilesAPI.Lookup")
    Dim iValueListID : iValueListID = 127
    Dim oValueListItems : Set oValueListItems = Vault.ValueListItemOperations.GetValueListItems(iValueListID)
    Dim oValueListItem
    Dim oAdd
    Dim oItem
    
    For Each oLookup1 In oLookups1	
    	oAdd = 1
    
    	For Each oItem in oValueListItems
    		If oItem.Name = oLookup1.DisplayValue Then
    			oAdd = 0
    		End If
    	Next
    
    	If oAdd = 1 Then
    		Set oValueListItem = CreateObject("MFilesAPI.ValueListItem")
    		oValueListItem.Name = oLookup1.DisplayValue
    		Vault.ValueListItemOperations.AddValueListItem iValueListID, oValueListItem, False
    	End If
    
    	oAdd = 1
    
    	For Each oLookup2 in oLookups2
    		If oLookup2.DisplayValue = oLookup1.DisplayValue Then
    		oAdd = 0
    		Exit For
    		End If
    	Next
    
    	If oAdd = 1 Then
    		Dim oSearchCondition : Set oSearchCondition = CreateObject("MFilesAPI.SearchCondition")
    		Dim oSearchConditions : Set oSearchConditions = CreateObject("MFilesAPI.SearchConditions")
    		
    		oSearchCondition.Expression.SetValueListItemExpression 2, 0, Nothing
    		oSearchCondition.ConditionType = 1
    		oSearchCondition.TypedValue.SetValue 1, oLookup1.DisplayValue
    		oSearchConditions.Add -1, oSearchCondition
    
    		oSearchCondition.Expression.SetValueListItemExpression 5, 0, Nothing
    		oSearchCondition.ConditionType = MFConditionTypeEqual
    		oSearchCondition.TypedValue.SetValue MFDatatypeBoolean, false
    		oSearchConditions.Add -1, oSearchCondition
    		
    		Dim oSearchResults : Set oSearchResults = Vault.ValueListItemOperations.SearchForValueListItemsEx(iValueListID, oSearchConditions, True, 0, True)
    		Dim oSearchResult
    		Dim NewLookup : Set NewLookup = CreateObject("MFilesAPI.Lookup")
    
    		For Each oSearchResult In oSearchResults
    			NewLookup.Item = oSearchResult.ID
    			NewLookup.SetLatestVersion
    			oLookups2.Add -1, NewLookup
    		Next
    	End If
    Next 
    
    Dim oPropertyValue : Set oPropertyValue = CreateObject("MFilesAPI.PropertyValue")
    
    oPropertyValue.TypedValue.SetValueToMultiSelectLookup(oLookups2)
    oPropertyValue.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.ZugehrigeObjektedocufill")
    Call Vault.ObjectPropertyOperations.SetProperty(ObjVer, oPropertyValue)

Reply
  • Got it working, here's the code Slight smile

    Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    Dim oLookups1 : Set oLookups1 = PropertyValues.SearchForPropertyByAlias(Vault, "PD.ZugehoerigeObjekte", True).TypedValue.GetValueAsLookups
    Dim oLookup1 : Set oLookup1 = CreateObject("MFilesAPI.Lookup")
    Dim oLookups2 : Set oLookups2 = CreateObject("MFilesAPI.Lookups")
    Dim oLookup2 : Set oLookup2 = CreateObject("MFilesAPI.Lookup")
    Dim iValueListID : iValueListID = 127
    Dim oValueListItems : Set oValueListItems = Vault.ValueListItemOperations.GetValueListItems(iValueListID)
    Dim oValueListItem
    Dim oAdd
    Dim oItem
    
    For Each oLookup1 In oLookups1	
    	oAdd = 1
    
    	For Each oItem in oValueListItems
    		If oItem.Name = oLookup1.DisplayValue Then
    			oAdd = 0
    		End If
    	Next
    
    	If oAdd = 1 Then
    		Set oValueListItem = CreateObject("MFilesAPI.ValueListItem")
    		oValueListItem.Name = oLookup1.DisplayValue
    		Vault.ValueListItemOperations.AddValueListItem iValueListID, oValueListItem, False
    	End If
    
    	oAdd = 1
    
    	For Each oLookup2 in oLookups2
    		If oLookup2.DisplayValue = oLookup1.DisplayValue Then
    		oAdd = 0
    		Exit For
    		End If
    	Next
    
    	If oAdd = 1 Then
    		Dim oSearchCondition : Set oSearchCondition = CreateObject("MFilesAPI.SearchCondition")
    		Dim oSearchConditions : Set oSearchConditions = CreateObject("MFilesAPI.SearchConditions")
    		
    		oSearchCondition.Expression.SetValueListItemExpression 2, 0, Nothing
    		oSearchCondition.ConditionType = 1
    		oSearchCondition.TypedValue.SetValue 1, oLookup1.DisplayValue
    		oSearchConditions.Add -1, oSearchCondition
    
    		oSearchCondition.Expression.SetValueListItemExpression 5, 0, Nothing
    		oSearchCondition.ConditionType = MFConditionTypeEqual
    		oSearchCondition.TypedValue.SetValue MFDatatypeBoolean, false
    		oSearchConditions.Add -1, oSearchCondition
    		
    		Dim oSearchResults : Set oSearchResults = Vault.ValueListItemOperations.SearchForValueListItemsEx(iValueListID, oSearchConditions, True, 0, True)
    		Dim oSearchResult
    		Dim NewLookup : Set NewLookup = CreateObject("MFilesAPI.Lookup")
    
    		For Each oSearchResult In oSearchResults
    			NewLookup.Item = oSearchResult.ID
    			NewLookup.SetLatestVersion
    			oLookups2.Add -1, NewLookup
    		Next
    	End If
    Next 
    
    Dim oPropertyValue : Set oPropertyValue = CreateObject("MFilesAPI.PropertyValue")
    
    oPropertyValue.TypedValue.SetValueToMultiSelectLookup(oLookups2)
    oPropertyValue.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.ZugehrigeObjektedocufill")
    Call Vault.ObjectPropertyOperations.SetProperty(ObjVer, oPropertyValue)

Children
  • And here's the code for writing a specific property (in this case "PD.Bezeichnung") of the Object Lookup into the Text Lookup..

    Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    Dim oLookups1 : Set oLookups1 = PropertyValues.SearchForPropertyByAlias(Vault, "PD.ZugehoerigeObjekte", True).TypedValue.GetValueAsLookups
    Dim oLookup1 : Set oLookup1 = CreateObject("MFilesAPI.Lookup")
    Dim oLookups2 : Set oLookups2 = CreateObject("MFilesAPI.Lookups")
    Dim oLookup2 : Set oLookup2 = CreateObject("MFilesAPI.Lookup")
    Dim iValueListID : iValueListID = 127
    Dim oValueListItems : Set oValueListItems = Vault.ValueListItemOperations.GetValueListItems(iValueListID)
    Dim oValueListItem
    Dim oAdd
    Dim oItem
    Dim oObjId : Set oObjId = CreateObject("MFilesAPI.ObjID")
    Dim oObjVerAndProps
    Dim oBezeichnung
    
    For Each oLookup1 In oLookups1
    	
    	Call oObjId.SetIDs(oLookup1.ObjectType, oLookup1.Item)
    	Set oObjVerAndProps = vault.ObjectOperations.GetLatestObjectVersionAndProperties(oObjId, true)
    	oBezeichnung = oObjVerAndProps.Properties.SearchForPropertyByAlias(Vault, "PD.Bezeichnung", True).TypedValue.DisplayValue
    	
    	oAdd = 1
    
    	For Each oItem in oValueListItems
    		If oItem.Name = oBezeichnung Then
    			oAdd = 0
    		End If
    	Next
    
    	If oAdd = 1 Then
    		Set oValueListItem = CreateObject("MFilesAPI.ValueListItem")
    		oValueListItem.Name = oBezeichnung
    		Vault.ValueListItemOperations.AddValueListItem iValueListID, oValueListItem, False
    	End If
    
    	oAdd = 1
    
    	For Each oLookup2 in oLookups2
    		If oLookup2.DisplayValue = oBezeichnung Then
    		oAdd = 0
    		Exit For
    		End If
    	Next
    
    	If oAdd = 1 Then
    		Dim oSearchCondition : Set oSearchCondition = CreateObject("MFilesAPI.SearchCondition")
    		Dim oSearchConditions : Set oSearchConditions = CreateObject("MFilesAPI.SearchConditions")
    		
    		oSearchCondition.Expression.SetValueListItemExpression 2, 0, Nothing
    		oSearchCondition.ConditionType = 1
    		oSearchCondition.TypedValue.SetValue 1, oBezeichnung
    		oSearchConditions.Add -1, oSearchCondition
    
    		oSearchCondition.Expression.SetValueListItemExpression 5, 0, Nothing
    		oSearchCondition.ConditionType = MFConditionTypeEqual
    		oSearchCondition.TypedValue.SetValue MFDatatypeBoolean, false
    		oSearchConditions.Add -1, oSearchCondition
    		
    		Dim oSearchResults : Set oSearchResults = Vault.ValueListItemOperations.SearchForValueListItemsEx(iValueListID, oSearchConditions, True, 0, True)
    		Dim oSearchResult
    		Dim NewLookup : Set NewLookup = CreateObject("MFilesAPI.Lookup")
    
    		For Each oSearchResult In oSearchResults
    			NewLookup.Item = oSearchResult.ID
    			NewLookup.SetLatestVersion
    			oLookups2.Add -1, NewLookup
    		Next
    	End If
    Next
    
    Dim oPropertyValue : Set oPropertyValue = CreateObject("MFilesAPI.PropertyValue")
    
    oPropertyValue.TypedValue.SetValueToMultiSelectLookup(oLookups2)
    oPropertyValue.PropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.ZugehrigeObjektedocufill")
    Call Vault.ObjectPropertyOperations.SetProperty(ObjVer, oPropertyValue)