Available VBScript Variables

VBScript code is edited in the Edit VBScript code window available in the following dialogs: The available variables are described in the table below.
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.
Note: The M-Files API documentation is available online: M-Files API.
Variable Data type Mode Use
ActivityID MFilesAPI.TypedValue In The unique ID of the operation that is being processed. Can be used for identifying which events are caused by a certain server operation.
AllowStateTransition Boolean Out Can be used to allow or deny automatic state transition when running the automatic state transition script.
CurrentTransactionID MFilesAPI.TypedValue In The ID of the transaction. If event handlers are executed recursively (so that executing one causes another to be executed), the ID changes on every recursion level.
CurrentUserID MFilesAPI.Number In Contains the ID of the user who performed the action that triggered the script.
CurrentUserSessionInfo MFilesAPI.SessionInfo In Contains information about the login session of the user who caused the operation.
DisplayID MFilesAPI.TypedValue In Contains the object's unique ID. This ID is shown on the object's metadata card when the object is selected in the list. DisplayID can contain both numbers and letters. Often, DisplayID is the same as the object's internal ID whose value can be retrieved with the ObjVer variable. The internal ID can only contain numbers. DisplayID and the internal ID are usually different when the object has been imported from an external database.
FileTransferSessionID MFilesAPI.Number In Contains the user-specific data transfer identifier. The data transfer identifier is created when the data transfer is being started on the server and, at the same time, the same identifier is given to the BeforeFileUpload and BeforeFileDownload event handlers. After completion of the data transfer, the same data transfer identifier will be given to the AfterFileUpload and AfterFileDownload event handlers. This way it is possible to attach the event handlers of type "Before" to the event handlers of type "After".
FileVer MFilesAPI.FileVer In Contains the complete unique ID of the target file, consisting of the file ID and file version.
GetExtensionObject (method) N/A A method for retrieving the extension object defined by the vault application.

Use: GetExtensionObject( <object name> [, application GUID]), where the part [, application GUID] is optional.

For example: Set CK = GetExtensionObject("M-Files.ComplianceKit", "{0CAC5452-631F-4646-AC95-4A06BFB8147E}")

If the application GUID has not been specified, the extension object is searched from all the applications of the vault.

GroupID MFilesAPI.Number In The ID of the target user group.
Input MFilesAPI.TypedValue In A client-defined parameter for the VaultExtensionMethod event handler.
IsCancellable MFilesAPI.BooleanValue In Normally, scripts can cancel a server operation and revert the associated transaction by raising an error in the script. The IsCancellable variable specifies whether the script is allowed do this.

If the value of the variable is false, M-Files Server will ignore any errors raised in the script. If the script raises an error while the value of the variable is false, however, an error is written to the Windows event log and all the changes made through the script are reverted. The server operation then proceeds to completion.

LastUsed MFilesAPI.TypedValue In Available only if a customized automatic number is being calculated for a property. The value of an automatic number usually depends on the previous calculation. For example, in ordinary consecutive numbering, the automatic value is incremented by one each time. When you are setting up customized automatic numbering, the result of the previous calculation can be retrieved by using the LastUsed variable.

For example, simple automatic numbering that increments by one could be implemented with the following simple VBScript code: Output = LastUsed + 1

LoggedOutUserID MFilesAPI.Number In Contains the logged out user ID after logout.
LoginAccount MFilesAPI.LoginAccount In Contains the user account data in the login.
MasterTransactionID MFilesAPI.TypedValue In The ID of the transaction. If event handlers are executed recursively (so that executing one causes another to be executed), this transaction ID is the ID of the first transaction.
MemberID MFilesAPI.Number In The ID of the member who is added to or removed from a user group. The value is negative if the member is a user group.
MFScriptCancel MFilesAPI.Number In Contains the error code which is used by the scripts for displaying error messages to users. M-Files often adds detailed data to error messages; this can be prevented with the error code of the MFScriptCancel variable.

Example: Err.Raise MFScriptCancel, "This is the error message shown to the user."

NextStateID MFilesAPI.Number Out During the automatic state transition, the NextStateID variable contains the ID of the state for which the automatic state transition will be performed. By changing the value of this variable, you can define the next state in the automatic state transition script. By default, the target state is the same as set in the Next State option in the user interface.
ObjectAccessControlList MFilesAPI.ObjectAccessControlList In Contains the current permissions of the viewed object.
ObjID MFilesAPI.ObjID In The ID of the object being processed.
ObjVer MFilesAPI.ObjVer In Contains the complete unique ID of the target version, consisting of the object type ID, object internal ID, and object version.
Output MFilesAPI.TypedValue Out Available only if a customized automatic number is being calculated for a property. When VBScript code starts to run, the Output variable contains the current value of the property being calculated (but not for automatic numbering).

The main purpose of VBScript code is usually to create a new value and assign it to the Output variable, which is then stored in the object's metadata. If the VBScript code does not set the value of the Output variable, the property value in the metadata remains the same.

The value of the Output variable can, in simple cases, be set with a simple statement, for example: Output = 123

If the data type of the value being calculated is, say, Choose from list, the SetValue method is recommended for setting the value of the Output variable (see M-Files API), for example, as follows: Output.SetValue MFDatatypeLookup, 101

ParentTransactionID MFilesAPI.TypedValue In The ID of the transaction. If event handlers are executed recursively (so that executing one causes another to be executed), this transaction ID is the ID of the previous (calling) transaction.
PropertyDef MFilesAPI.PropertyDef In Contains the information about the property value being calculated, such as the property value definition ID, name, and data type.
PropertyValue MFilesAPI.PropertyValue In Contains a property value. Each property value is stored in the PropertyValues variable as a variable of the type PropertyValue. A certain property value can be retrieved with the SearchForProperty method.
PropertyValues MFilesAPI.PropertyValues In Contains all the property values of the target version that were affected by the current action. Each property value is stored in the variable PropertyValues as a variable of the type PropertyValue. A certain property value can be retrieved with the SearchForProperty method.
Note: Some property definitions are not shown when using the PropertyValues variable in scripts (see Property definitions not shown for scripts).
RestoredVersions MFilesAPI.IDs In Contains object versions of the exported object that were imported from the content package.
SavepointVariables MFilesAPI.NamedValues In/Out A container for optional name-value pairs stored for the duration of a single transaction. The container automatically reverts the modifications caused by failed operations in the container.
ScheduledJob MFilesAPI.ScheduledJob In Contains a description of the scheduled job which is being performed.
ScheduledJobOutputInfo MFilesAPI.ScheduledJobOutputInfo In Contains information of the scheduled job result after the job has been performed.
StateID MFilesAPI.Number In Contains the workflow state identifier which can be used to recognize the process state in scripts related to the workflows.
StateTransitionID MFilesAPI.Number In The ID of the state transition.
TransactionCache MFilesAPI.NamedValues In/Out A container for optional name-value pairs stored for the duration of a single transaction. The container retains all the modifications, even if they were caused by an operation that was later canceled due to an error.
UserAccount MFilesAPI.UserAccount In Vault user information.
UserGroupAdmin MFilesAPI.UserGroupAdmin In Vault user group information.
ValueListItem MFilesAPI.ValueListItem In Contains the value list value which is being processed in the event handler.
Vault MFilesAPI.Vault In Represents the document vault used in running the script. With the identifier, the script is able to handle the document vault contents in the same way as is possible with the M-Files API interface. In an error situation, all changes made to the document vault through the Vault entity will be cancelled.

The use of the Vault entity with scripts entails certain limitations. The scripts cannot, through the Vault entity, change the state of the object which the script is run to. The state change refers to checking out the object, checking in the object, undoing the check-out, and deleting and destroying the object. Also, all other objects that are checked out in the script must be checked in during running of the same script.

VaultSharedVariables MFilesAPI.NamedValues In/Out A collection of named values stored in the document vault database. With the variable, the scripts can store their own values in the database so that they are also available to other scripts. The allowed data types for the named values are integer variables, Booleans, and strings.

In the following example, the value 123 is stored as a named value and the number-based calculated value is then set as the value.

VaultSharedVariables( "Message" ) = 123

Output = VaultSharedVariables( "Message" )

View MFilesAPI.View In Contains the view which is being processed in the event handler.

Property definitions not shown for scripts

The property definitions listed in the following table are not shown by using the PropertyValues variable in scripts:

ID Name
24 Status changed
22 Single file
27 Deleted
28 Deleted by
33 Comment
29 Version label
30 Size on server (this version)
31 Size on server (all versions)
32 Marked for archiving
46 Collection members (documents)
47 Collection members (document collections)
101 Class groups
41 Assignment description
42 Deadline
43 Monitored by
44 Assigned to
45 Marked as complete by
97 Marked as rejected by
79 Workflow Assignment
81 Accessed by me
82 Favorite view
89 Object changed
90 Permissions changed
91 Version label changed
92 Version comment changed
93 Deletion status changed
96 Conflict resolved
105 Object changed for export
106 Object version changed for export

For example, the following piece of script results in a "not found" error:

Dim DeadlineValue
DeadlineValue = PropertyValues.SearchForProperty(42).TypedValue.DisplayValue
Tip: You can use the GetProperties method to get all the properties of a specific object.