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:

  1. Property value validation
  2. Calculating automatic property values
  3. The BeforeCreateNewObjectFinalize event
  4. Workflow state preconditions
  5. Workflow state actions
  6. The BeforeCheckInChangesFinalize event
  7. The AfterCreateNewObjectFinalize event
  8. The AfterCheckInChangesFinalize event

The user creates an object, edits its property values, and checks in the object:

  1. Property value validation
  2. Calculating automatic property values
  3. The BeforeCreateNewObjectFinalize event
  4. The AfterCreateNewObjectFinalize event
  5. The BeforeSetProperties event
  6. Property value validation
  7. Calculating automatic property values
  8. The AfterSetProperties event
  9. The BeforeFileUpload event
  10. The AfterFileUpload event
  11. The BeforeSetProperties event
  12. Calculating automatic property values
  13. The AfterSetProperties event
  14. The BeforeCheckInChanges event
  15. Workflow state preconditions
  16. Workflow state actions
  17. The BeforeCheckinChangesFinalize event
  18. The AfterCheckInChanges event
  19. The AfterCheckInChangesFinalize event

The user edits the property values and changes the workflow state of an object:

  1. The BeforeCheckOut event
  2. The AfterCheckOut event
  3. The BeforeSetProperties event
  4. Property value validation
  5. Calculating automatic property values
  6. The AfterSetProperties event
  7. The BeforeCheckInChanges event
  8. Previous workflow state postconditions
  9. New workflow state preconditions
  10. Workflow state actions
  11. The BeforeCheckinChangesFinalize event
  12. The AfterCheckInChanges event
  13. The AfterCheckInChangesFinalize event
  14. 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:

  1. Property value validation
  2. Calculating automatic property values
  3. The BeforeCreateNewObjectFinalize event
  4. Workflow state preconditions
  5. Workflow state actions
  6. The BeforeCheckInChangesFinalize event
  7. The AfterCreateNewObjectFinalize event
  8. INSERT action to the external database
  9. The AfterCheckInChangesFinalize event