M-File Automatic Value VBScript

We're trying to create a property of Datatype "Choose from list (multi-select)" with an automatic value based on other properties that the object has. For instance, we have a property "A" with a value of two different employee names both chosen from a list of people. There is also a property "B" with one name of a different employee name chosen from the same list. The property we're trying to create (let's call it property "C") would automatically have the value of any names in "A" and "B" (so in this case, it would have a value of 3 employee names; two from "A" and one from "B"). I've been digging into VBScript and trying to figure out how to make this work, but I'm getting an error. It appears that something is wrong with the "For Each" loops I'm trying to use. Is there someone who knows how to write this in a VBScript for a property automatic value that could point me in the right direction? I've included the text of the script I'm writing, and the error message that is thrown when I try to use this property. (The property is called "RACI Consolidation" in the error message.)

VBScript: 

Option Explicit

Dim szR 
szR = PropertyValues.SearchForProperty(1454)
Dim szA
szA = PropertyValues.SearchForProperty(1455)
Dim szC
szC = PropertyValues.SearchForProperty(1456)
Dim szI
szI = PropertyValues.SearchForProperty(1457)

Dim szConsolidated
Dim subItem : Set subItem  = CreateObject("MFilesAPI.Lookup")

'add any items in szR (if any) to szConsolidated
For Each subItem In szR
    szConsolidated.Add -1, subItem 
Next

For Each subItem In szA
    szConsolidated.Add -1, subItem 
Next

For Each subItem In szC
    szConsolidated.Add -1, subItem 
Next

For Each subItem In szI
    szConsolidated.Add -1, subItem 
Next


Output = szConsolidated

Error message:

<MetadataEditor>, -, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
ScriptErrorHelper.cpp, 96, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MDispatchExImpl.h, 679, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MDispatchExImpl.h, 841, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MetadataCardAction.cpp, 386, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MetadataCardAction.cpp, 560, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MetadataEditor.cpp, 2956, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MetadataModel.cpp, 4488, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MetadataModel.cpp, 4939, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
ElectronicSignatureUIHelper.cpp, 239, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MetadataModel.cpp, 12646, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
CoVaultMountingDocumentOperations.cpp, 3296, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
CoVaultMountingDocumentOperations.cpp, 3384, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
DocumentCache.cpp, 11824, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
DocumentCache.cpp, 11935, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
DocumentCache.cpp, 20389, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCMethodCallWithRetry.h, 36, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCMethodCallWithRetry.h, 36, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCDocumentOperations.cpp, 12771, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCDocumentOperations.cpp, 7253, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
MCallInLoop.h, 535, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCDocumentOperationsHelper.cpp, 4538, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCDocumentOperationsHelper.cpp, 3998, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCDocumentOperationsHelperPrivate.cpp, 7658, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RPCDocumentOperationsHelperPrivate.cpp, 7459, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RecalculateProperties.cpp, 446, Calculation of the automatic value of the property "RACI Consolidation" failed. (0x80040107)
RecalculateProperties.cpp, 446, Script execution failed. ((RACI Consolidation, PropertyDefCalculatedValue: 215-4-2)) (0x800408BB)
RecalculateProperties.cpp, 1651, Script execution failed. ((RACI Consolidation, PropertyDefCalculatedValue: 215-4-2)) (0x800408BB)
RecalculateProperties.cpp, 1468, Script execution failed. ((RACI Consolidation, PropertyDefCalculatedValue: 215-4-2)) (0x800408BB)
RecalculateProperties.cpp, 1718, Script execution failed. ((RACI Consolidation, PropertyDefCalculatedValue: 215-4-2)) (0x800408BB)
RecalculateProperties.cpp, 1412, Script execution failed. ((RACI Consolidation, PropertyDefCalculatedValue: 215-4-2)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 277, Script execution failed. ((RACI Consolidation, PropertyDefCalculatedValue: 215-4-2)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 342, Script execution failed. ((RACI Consolidation, PropertyDefCalculatedValue: 215-4-2)) (0x800408BB)
VaultScriptSessionTemplates.cpp, 342, Object doesn't support this property or method (0x80040008)
VaultScriptSessionTemplates.cpp, 524, Object doesn't support this property or method (0x80040008)
CoActiveScriptSite.cpp, 897, Object doesn't support this property or method (0x80040008)
CoActiveScriptSite.cpp, 739, Object doesn't support this property or method (0x80040008)
RACI Consolidation, PropertyDefCalculatedValue, 16, Object doesn't support this property or method (0x80040008)
MErrorHelper.cpp, 2347, Object doesn't support this property or method (0x80040008)
(M-Files 23.12.13247.4 2024-08-27T21:16:08.422Z)

  • The stack shows that the error is on line 16:

    RACI Consolidation, PropertyDefCalculatedValue, 16, Object doesn't support this property or method (0x80040008)

    It looks like "szR" is a TypedValue instance.  You can't iterate over a TypedValue instance.  I assume you want "szConsolidated" to be a Lookups collection but it's not instantiated.  Do you then want to iterate over "szR.GetValueAsLookups", maybe?

    I then assume you want all of the rest of the code to be modified in a similar manner (for "szA", "szC", "szI"...).  You may also need a "Set" before your final line, I don't recall (I don't use VBScript much) any more.

    To that point I would probably try to guide you towards using the Vault Application Framework rather than VBScript.  At some point in the future Microsoft will remove VBScript from Windows, at which point you may find updating the server OS difficult as is causes your code to break.  Using the VAF is a much more future-proof solution.

  • I got some help on a couple parts of this, and here's the final working script we've implemented. (This will work for our short term needs -- I'll work to figure out how to use the Vault Application Framework so we can migrate our existing VBScript to that format.)

    Option Explicit
    
    Dim szR : szR = 1454 
    Dim szA : szA = 1455
    Dim szC : szC = 1456
    Dim szI : szI = 1457
    
    Dim subItems : Set subItems  = CreateObject("MFilesAPI.Lookups")
    Dim subItem : Set subItem  = CreateObject("MFilesAPI.Lookup")
    
    'add any items in szR (if any) to subItems
    For Each subItem In Vault.ObjectPropertyOperations.GetProperty(ObjVer, szR).Value.GetValueAsLookups
    	'checks to see if this value already exists in subItems
    	If subItems.GetLookupIndexByItem(subItem.Item) = -1 Then
    		'add value to list of subItems
    		subItems.Add -1, subItem
    	End If
    Next
    
    For Each subItem In Vault.ObjectPropertyOperations.GetProperty(ObjVer, szA).Value.GetValueAsLookups
    	If subItems.GetLookupIndexByItem(subItem.Item) = -1 Then
    		subItems.Add -1, subItem
    	End If
    Next
    
    
    For Each subItem In Vault.ObjectPropertyOperations.GetProperty(ObjVer, szC).Value.GetValueAsLookups
    	If subItems.GetLookupIndexByItem(subItem.Item) = -1 Then
    		subItems.Add -1, subItem
    	End If
    Next
    
    
    For Each subItem In Vault.ObjectPropertyOperations.GetProperty(ObjVer, szI).Value.GetValueAsLookups
    	If subItems.GetLookupIndexByItem(subItem.Item) = -1 Then
    		subItems.Add -1, subItem
    	End If
    Next
    
    Output = subItems