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
  • Unfortunately, working with Lookups is not easy. You will need to do something like the example below:

    '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.Teams")
    
    'Create Empty Lookup and Collection
    Set oTeamLookupObj = CreateObject("MFilesAPI.Lookup")
    Set oCollectionOfTeamsLookupsObj = CreateObject("MFilesAPI.Lookups")
    
    'Loop in Teams Array of IDs
    
    For Each teamID in TeamIDsArray
    	oTeamLookupObj.Item = teamID
    	oCollectionOfTeamsLookupsObj.Add -1, oTeamLookupObj
    Next
    
    'Now new Lookups Collection was created, let's assign it
    oPropVals.SearchForProperty(iPDTeams).TypedValue.SetValue MFDatatypeMultiSelectLookup, oCollectionOfTeamsLookupsObj
    
    'Commit All properties
    Vault.ObjectPropertyOperations.SetAllProperties ObjVer, True, oPropVals
    
    'End of Script
    ' Instead of an empty collection you can take the current one, but you should be careful about duplicate values: 
    ' Set oCollectionOfTeamsLookupsObj = oPropVals.SearchForProperty(iPDTeams).TypedValue.GetValueAsLookups()

    And as Craig said:
    "Code written off the top of my head, without Visual Studio, before coffee, so there may be a couple of issues!"

  • Joy Beautiful description of the pre-early morning state of mind.

Reply Children
No Data