Editing VBScript Code

Creating customized automatic values and calculated values can be specified in more detail by using M-Files API and generic features of VBScript. This section provides additional instructions for using VBScript with automatic values.

Note: Automatic properties can also be created for objects so that the calculated properties include not only the object's properties, but also those of another object related to the current object. For example, if the property Customer has been attached to the project but not to the document, an automatic name can be given to the document based on the properties of the document, the project, or both. The automatic name of the document can follow, for instance, the format House plan Star / ESTT.

Creating automatic values with VBScript

VBScript code is edited in the Edit VBScript code window. The code is executed whenever a property value is recalculated; in other words, whenever a property is edited. VBScript creates the value and finally assigns it to a variable called Output. This value is stored as the value of the property in the object metadata.

The simplest piece of VBScript to formulate an automatic value might 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, refer to VBScript Variables Explained.

Sample code

The following sample code creates an automatic value for the "Proposal Title" property by utilizing the proposal number and customer information in the object version metadata. The ID of the Proposal Number property is 1156 and the ID of the Customer property is 1288. For example, 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

Note: The documentation for the M-Files API is located in Start > Programs > M-Files > Documentation > M-Files API. For more information about VBScript code and M-Files API, go to www.m-files.com/api. Instructions on writing VBScript code and working with the M-Files API are available for a separate fee from M-Files customer support ([email protected]).