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!"

  • Thanks for this code! We are very close to a solution here, but I might have left out a critical piece of data that might be why I am getting an error.

    The Property we are trying to set references an object. So while the property is Property ID 1686 (PD.Teams) the valuelist is based off an object which essentially builds a valuelist ID 395.

    When I run the script I get an error that says: The value "395-192" does not exist, or it is a conflict object."

    The iPDTeams from your code returns 1686 since that is the propertyDef ID.

    Do I need to refer to the property differently since it is referencing values from a list automatically populated by an object's members?

    I hope I'm explaining this correctly.

Reply
  • Thanks for this code! We are very close to a solution here, but I might have left out a critical piece of data that might be why I am getting an error.

    The Property we are trying to set references an object. So while the property is Property ID 1686 (PD.Teams) the valuelist is based off an object which essentially builds a valuelist ID 395.

    When I run the script I get an error that says: The value "395-192" does not exist, or it is a conflict object."

    The iPDTeams from your code returns 1686 since that is the propertyDef ID.

    Do I need to refer to the property differently since it is referencing values from a list automatically populated by an object's members?

    I hope I'm explaining this correctly.

Children
  • If I understood correctly, at a certain step of the workflow you try to set specific items from the object teams, for example the responsible teams. In this situation, they must already exist in Teams Object. Can you provide all the code you run?

    Also in my code above is in line 20 it is better to use

    oPropVals.SearchForProperty(iPDTeams).TypedValue.SetValueToMultiSelectLookup oCollectionOfTeamsLookupsObj 

    instead

    oPropVals.SearchForProperty(iPDTeams).TypedValue.SetValue MFDatatypeMultiSelectLookup, oCollectionOfTeamsLookupsObj 

  • I made a few minor tweaks to match up with your recommendation to use Alias and I also caught the change you reference above. Here is the code as it stands right now which gives the error:

    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")
    'Set oCollectionOfTeamsLookupsObj = CreateObject("MFilesAPI.Lookups")
    Dim oCollectionOfTeamsLookupsObj: Set oCollectionOfTeamsLookupsObj = oPropVals.SearchForProperty(iPDTeams).TypedValue.GetValueAsLookups()
    
    Dim TeamIDsArray: TeamIDsArray = Array(192, 196, 189)
    Dim teamID
    
    '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.SetValueToMultiSelectLookup oCollectionOfTeamsLookupsObj
    
    
    'Commit All properties
    Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, oPropVals