Document Vault Administration / Document Vault Action Menu |
With Event handlers you can define different operations that are performed when editing objects. The operations are specified using variables, generic features of VBScript, and M-Files API.
You can create and edit event handlers in M-Files Admin: Activate the document vault that you want to define event handlers for. You can then find the event handlers in the Action menu or by right-clicking the vault. You can add several different operations to the same event handler by naming them separately.
The documentation for the M-Files API is installed in the folder Start > Programs > M-Files > Documentation > M-Files API. For more information about VBScript code and M-Files API, contact [email protected]. Instructions on writing VBScript code and working with the M-Files API are available from the M-Files technical support staff for a separate fee.
Example
When creating a new object, the event handler can be used to check, for example, whether the document vault already contains an object with that title. If it does, the user receives an error message. In this case, the VBScript code follows the following format (the example only in English):
' The ID of the title property.
Dim titleProperty
titleProperty = MFBuiltInPropertyDefNameOrTitle
' Find the title property of the current object.
Dim currentTitleProp
currentTitleProp = PropertyValues.SearchForProperty(titleProperty)
' Get the title of the object.
Dim currentTitle
currentTitle = currentTitleProp.Value
' Search for objects on the basis of title.
Dim titleSearch
Set titleSearch = CreateObject("MFilesAPI.SearchCondition")
Dim titleExpression
Set titleExpression = CreateObject("MFilesAPI.Expression")
titleExpression.SetTypedValueExpression MFDatatypeText, -1, MFParentChildBehaviorNone, Nothing
Dim titleTypedValue
Set titleTypedValue = CreateObject("MFilesAPI.TypedValue")
titleTypedValue.SetValue MFDatatypeText, currentTitle
titleSearch.Set titleExpression, MFConditionTypeEqual, titleTypedValue
Dim SearchResults
Set SearchResults = Vault.ObjectSearchOperations.SearchForObjectsByCondition(titleSearch, false)
' If an existing object with the same title was found, raise an error.
If SearchResults.Count > 1 Then
Err.Raise MFScriptCancel, _
"The document vault already contains an object with the same title."
End if