Specifying an Automatic Property Value Using VBScript

Creating customized automatic values and calculated values can be specified in more detail with M-Files API and generic features of VBScript ("Microsoft Visual Basic Scripting Edition"). This section gives instructions on how to use VBScript with automatic values. For the VBScript user's guide and language reference, see the VBScript MSDN article.

Note: When you develop new extensions or edit existing ones, we recommend that you replace VBScript content with Vault Application Framework (VAF) compatible code for future compatibility. For more information on the benefits of VAF development over VBScript, refer to The Vault Application Framework in M-Files Developer Portal.

The VBScript code for a calculated value is executed whenever a property value is edited. The VBScript code is used for calculating the automatic value, after which the result of the calculation must be assigned to a variable called Output. This value is stored as the value of the property in the object metadata.

The simplest piece of VBScript for formulating an automatic value might therefore look like this:

Output = "Automatic value"

Usually an automatic value uses other object properties, for example, by concatenating them. VBScript code can use the property values and basic information of the same or another object with these VBScript variables:

  • CurrentUserID
  • DisplayID
  • LastUsed
  • MFScriptCancel
  • ObjVer
  • Output
  • PropertyDef
  • PropertyValues
  • Vault
  • VaultSharedVariables
For the variable descriptions, see Available VBScript Variables.
Note: Some property definitions are not shown when using the PropertyValues variable in scripts (see Property definitions not shown for scripts).

Do the following steps to use VBScript for calculating an automatic value for a property:

  1. Open M-Files Admin.
  2. In the left-side tree view, expand a connection to M-Files server.
  3. Expand Document Vaults.
  4. Expand a vault.
  5. Expand Metadata Structure (Flat View) and then select Property Definitions.
    Result:The Property Definitions list is opened in the right pane.
  6. Double-click the property definition that you want to edit.
    Result:The Property Definition Properties dialog is opened.
  7. Go to the Automatic Values tab.
    Result:The Automatic Values tab is opened.
  8. Select either:
    • Customized automatic numbering (VBScript): Select this option if you want to define automatic numbering using VBScript.
      or
    • Calculated value (VBScript): Select this option if you want to define any other type of automatic value using VBScript.
  9. Click Edit Code.
    Result:The Edit VBScript Code window is opened.
  10. Specify the VBScript code for calculating the automatic value. For instructions, see Specifying an Automatic Property Value Using VBScript.
    Example:The following code creates an automatic value for the "Proposal Title" property by utilizing the proposal number and customer information in the object metadata. The ID of the Proposal Number property is 1156 and the ID of the Customer property is 1288. If a document has the proposal number 5577 and the customer is ESTT, the code below creates the following string as the title of the proposal: "Proposal #5577 / ESTT".
    Option Explicit
    
    ' Get proposal number.
    
    Dim szNumber
    szNumber = PropertyValues.SearchForProperty( 1156 ).TypedValue.DisplayValue
    
    ' Get customer.
    
    Dim szCustomer
    szCustomer = PropertyValues.SearchForProperty( 1288 ).TypedValue.DisplayValue
    
    ' Create proposal title.
    
    Dim szName
    szName = "Proposal #" & szNumber & " / " & szCustomer
    
    ' Set result.
    
    Output = szName
  11. Close the Edit VBScript Code window once you are done.
  12. Back in the Property Definition Properties dialog, click OK to save your changes and to close the Property Definition Properties dialog.
The selected property now has an automatic value which is calculated by the VBScript code that you have specified.