Execution order of scripts
M-Files executes user-specified scripts in a specific order based on the event for which the script is written. The lists given here show the default event order for common vault actions.
Important to note:
- The exact order and number of events depend on the vault structure and the types of scripts used.
- M-Files Custom Agents actions run only after the transaction containing the state transition commits. If a state has one configured, it always runs after every event in that transaction, including every example sequence on this page. For more information, refer to M-Files Custom Agents (Beta) - Admin Guide.
Execution order examples
The user creates an object and immediately checks it in:
- Property value validation
- Calculating automatic property values
- The BeforeCreateNewObjectFinalize event
- Workflow state preconditions
- Workflow state actions
- The BeforeCheckInChangesFinalize event
- The AfterCreateNewObjectFinalize event
- The AfterCheckInChangesFinalize event
The user creates an object, edits its property values, and checks in the object:
- Property value validation
- Calculating automatic property values
- The BeforeCreateNewObjectFinalize event
- The AfterCreateNewObjectFinalize event
- The BeforeSetProperties event
- Property value validation
- Calculating automatic property values
- The AfterSetProperties event
- The BeforeFileUpload event
- The AfterFileUpload event
- The BeforeSetProperties event
- Calculating automatic property values
- The AfterSetProperties event
- The BeforeCheckInChanges event
- Workflow state preconditions
- Workflow state actions
- The BeforeCheckinChangesFinalize event
- The AfterCheckInChanges event
- The AfterCheckInChangesFinalize event
The user edits the property values and changes the workflow state of an object:
- The BeforeCheckOut event
- The AfterCheckOut event
- The BeforeSetProperties event
- Property value validation
- Calculating automatic property values
- The AfterSetProperties event
- The BeforeCheckInChanges event
- Previous workflow state postconditions
- New workflow state preconditions
- Workflow state actions
- The BeforeCheckinChangesFinalize event
- The AfterCheckInChanges event
- The AfterCheckInChangesFinalize event
- The BeforeReturnView event
If you have more than one event handler of the same type, you can change their execution order: Select the event handler in the Event Handlers dialog and use the up and down arrows to move it to a different spot.
Execution order for external object types
Operations in an external database are done as the second last action. For example, here is the execution order for when the user creates an external database object and checks it in:
- Property value validation
- Calculating automatic property values
- The BeforeCreateNewObjectFinalize event
- Workflow state preconditions
- Workflow state actions
- The BeforeCheckInChangesFinalize event
- The AfterCreateNewObjectFinalize event
- INSERT action to the external database
- The AfterCheckInChangesFinalize event