Specifying an Automatic Property Value Using VBScript

Creating customized automatic values and calculated values can be specified in more detail by using M-Files API and generic features of VBScript ("Microsoft Visual Basic Scripting Edition"). This section provides instructions for using VBScript with automatic values.

Note: For the VBScript user's guide and language reference, see the VBScript MSDN article.

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 utilize the property values and basic information of the same or another object with the aid of the following 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. In the left-side tree view, expand Document Vaults, and then expand a vault.
  4. Still in the left-side tree view, expand Metadata Structure (Flat View) and then select Property Definitions.
    Result:The Property Definitions list is opened in the right pane.
  5. Double-click the property definition that you want to edit.
    Result:The Property Definition Properties dialog is opened.
  6. Go to the Automatic Values tab.
    Result:The Automatic Values tab is opened.
  7. 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.
  8. Click the Edit Code... button.
    Result:The Edit VBScript Code window is opened.
  9. Specify the VBScript code for calculating the automatic value.
    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
  10. Close the Edit VBScript Code window once you are done.
  11. 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.