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.
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:
|
|
|
For the variable descriptions, refer to VBScript Variables Explained.
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