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

Setting known value to a Multi-Select property. Simple method.

I have a specific use-case where I need to add 3 known values to a multi-select property. I know the values, but the folder source can only add a single value. I plan to use a workflow state to add the additional 2 values automatically and move the document to the next state however there is no simple guide to adding the additional 2 properties. I do not need to look them up, I know their IDs I just need the simplest way to add them.

I've see the sample from Bright-Ideas to lookup values that are set on related documents and lock referenced document versions to the new document etc, but there is so much extra there.

I simply need something along these lines:

Dim oProperty : set oProperty = CreateObject("MFilesAPI.PropertyValue")
oProperty.PropertyDef = 1686 'Property to add

'IDs of the property valuelist to add to the metadata card for the object.
oProperty.TypedValue.SetValueToMultiSelectLookup Array(10, 31, 41)

' Upgrade the properties for the object
Dim oNullVer : Set oNullVer = Vault.ObjectPropertyOperations.SetProperty( ObjVer, oProperty )

As a bonus, saving the values that are already entered and ADDING the additional values would be useful, but not required.

Parents
  • bump - we are doing a migration, and need this ability before we can proceed. Thanks everyone!

  • Got it working! It turns out I needed to do a lookup as the displayed ID in the value list was not necessarily the same ID I needed to enter when populating the Lookup. Here is the now working code.

    Option Explicit
    
    'Get properties instance of current object
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    
    'Strongly recommend use GetPropertyDefIDByAlias instead numeric ID of Property
    Dim iPDTeams: iPDTeams = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.Team")
    
    'Create Empty Lookup and Collection
    Dim oTeamLookupObj: Set oTeamLookupObj = CreateObject("MFilesAPI.Lookup")
    
    'Dim oCollectionOfTeamsLookupsObj: Set oCollectionOfTeamsLookupsObj = CreateObject("MFilesAPI.Lookups")
    Dim oCollectionOfTeamsLookupsObj: Set oCollectionOfTeamsLookupsObj = oPropVals.SearchForProperty(iPDTeams).TypedValue.GetValueAsLookups		'instead of the above line, use this to get existing property values
    
    Dim arrTeamIDs: arrTeamIDs = Array(192, 196, 189)		'Array of Teams using the ID displayed in the value list.
    
    Dim vTeamID, oValueListItem, isUnique
    Dim oCheckItem : Set oCheckItem = CreateObject("MFilesAPI.Lookup")
    
    'Loop in Teams Array of IDs
    For Each vTeamID in arrTeamIDs
    	isUnique = 1
    	set oValueListItem = Vault.ValueListItemOperations.GetValueListItemByDisplayID(395, vTeamID)	'395 is the ID of the Teams Object
    	oTeamLookupObj.Item = oValueListItem.ID
    	
    	'Check if the value was already on the Metadata card
    	'and only add it if it is unique
    	For Each oCheckItem in oCollectionOfTeamsLookupsObj
    		if oCheckItem.Item = oTeamLookupObj.Item then isUnique = 0
    	Next
    	if isUnique = 1 then oCollectionOfTeamsLookupsObj.Add -1, oTeamLookupObj
    Next
    
    'Now new Lookups Collection was created, let's assign it
    oPropVals.SearchForProperty(iPDTeams).Value.SetValueToMultiSelectLookup oCollectionOfTeamsLookupsObj
    
    'Commit All properties
    Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, oPropVals
    

Reply
  • Got it working! It turns out I needed to do a lookup as the displayed ID in the value list was not necessarily the same ID I needed to enter when populating the Lookup. Here is the now working code.

    Option Explicit
    
    'Get properties instance of current object
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    
    'Strongly recommend use GetPropertyDefIDByAlias instead numeric ID of Property
    Dim iPDTeams: iPDTeams = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.Team")
    
    'Create Empty Lookup and Collection
    Dim oTeamLookupObj: Set oTeamLookupObj = CreateObject("MFilesAPI.Lookup")
    
    'Dim oCollectionOfTeamsLookupsObj: Set oCollectionOfTeamsLookupsObj = CreateObject("MFilesAPI.Lookups")
    Dim oCollectionOfTeamsLookupsObj: Set oCollectionOfTeamsLookupsObj = oPropVals.SearchForProperty(iPDTeams).TypedValue.GetValueAsLookups		'instead of the above line, use this to get existing property values
    
    Dim arrTeamIDs: arrTeamIDs = Array(192, 196, 189)		'Array of Teams using the ID displayed in the value list.
    
    Dim vTeamID, oValueListItem, isUnique
    Dim oCheckItem : Set oCheckItem = CreateObject("MFilesAPI.Lookup")
    
    'Loop in Teams Array of IDs
    For Each vTeamID in arrTeamIDs
    	isUnique = 1
    	set oValueListItem = Vault.ValueListItemOperations.GetValueListItemByDisplayID(395, vTeamID)	'395 is the ID of the Teams Object
    	oTeamLookupObj.Item = oValueListItem.ID
    	
    	'Check if the value was already on the Metadata card
    	'and only add it if it is unique
    	For Each oCheckItem in oCollectionOfTeamsLookupsObj
    		if oCheckItem.Item = oTeamLookupObj.Item then isUnique = 0
    	Next
    	if isUnique = 1 then oCollectionOfTeamsLookupsObj.Add -1, oTeamLookupObj
    Next
    
    'Now new Lookups Collection was created, let's assign it
    oPropVals.SearchForProperty(iPDTeams).Value.SetValueToMultiSelectLookup oCollectionOfTeamsLookupsObj
    
    'Commit All properties
    Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, oPropVals
    

Children
No Data