Set all values in a multi-select property with Vbscript

Hi,

I need to set all existing values in a multi-select property automatically via Vbscript, via a State in the stream or even in the event handler.
I have no idea how to proceed, could you provide me with some example script?

Thanks so much for any help!

  • Hi,

    According to the documentation https://www.m-files.com/api/documentation/#MFilesAPI~TypedValue~SetValueToMultiSelectLookup.html, it must be something like that:

    oProperties.SearchForProperty(iNewMultiSelectLookup).TypedValue.SetValueToMultiSelectLookup oMultiSelectLookupObject

  • You need to make sure you have all the lookups gathered before you attempt to set the propertyvalue.

    Here is a sample where I needed to take a list of documents from a property where they were listed with reference to latest version and copy it to another property listed explicitly with the version current at the time of copying.

    Dim oADoc, oADocs
    Set oADocs = Vault.ObjectPropertyOperations.GetProperty(ObjVer,<PropertyDef ID>).TypedValue.GetValueAsLookups()
    if Not oADocs.count = 0 then
    	Dim oBProp : set oBProp = CreateObject("MFilesAPI.Lookup")
    	Dim oBProps: Set oBProps = CreateObject("MFilesAPI.Lookups")
    	Dim oObjID: set oObjID = CreateObject("MFilesAPI.ObjID")
    	For Each oADoc In oADocs
    		oObjID.SetIDs 0, oADoc.Item '0 = object type Document
    		Dim oBObjVer: Set oBObjVer = Vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
    		Dim oBVersionX: oBVersionX = oBObjver.VersionEx.Version
    		oBProp.Item = oADoc.Item
    		oBProp.Version = oBVersionX ' Set to current version instead of -1
    		oBProps.Add -1, oBProp
    	Next
    End if
    'Set the values to the new property
    Dim thisProperty : set thisProperty = CreateObject("MFilesAPI.PropertyValue")
    thisProperty.PropertyDef = <new PropertyDef ID>
    thisProperty.TypedValue.SetValueToMultiSelectLookup oBProps
    ' Upgrade the properties for the object
    Dim oNullVer : Set oNullVer = Vault.ObjectPropertyOperations.SetProperty( ObjVer, thisProperty )