Execution Order of Scripts
User-specified scripts in M-Files are executed in a specific order and the point in which they are executed depends on the event for which the script is written. See the lists below for the order in which events are by default executed when a user does a certain action in a vault. Note that the exact order and number of events that are triggered after a specific user action depend on the vault structure and the types of scripts used in the vault.
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 by selecting the event handler in the Event Handlers dialog and clicking either the up or down arrow button along the right side of the dialog:
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