Share via


Order of Workflow Events

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Knowing when events occur and in what order they occur is important, because it affects how and when your script runs. For example, if you have two script procedures that are meant to run in a certain order, you must make sure the events the procedures are associated with occur in that order.

There are seven events: OnCreate, OnTransition, OnDelete, OnEnter, OnExit, OnChange, and OnTimeout. Each of these has two associated script procedures - validation and action. The validation script procedure must return True for the associated action script procedure to be executed.

If you have a series of events - such as for a transition where you exit state A, transition from state A to state B, and then enter state B - all validation procedures that are defined must return True before any action script is executed.

Note   If you do not have OnExit and OnEnter actions defined for the states involved in a transition, only the transition validation is executed.

The following sections explain the order that events are executed for the different types of workflow actions:

  • Creating a New Record

  • Deleting a Record

  • Entering and Exiting a State

  • Transition from One State to Another

  • Editing a Record

  • Remaining in a State for a Certain Time

For more information about scripting workflow events, see Scripting Workflow Actions.

Creating a New Record

The OnCreate event moves the item from a non-existent state to the initial state of New. By default, the first state in your workflow process has an OnCreate action available.

On the workflow diagram, OnCreate is displayed with its friendly name, New. It is displayed as a transition from the starting block to the state containing the OnCreate action.

Order of events

  • OnCreate Þ OnEnter

Deleting a Record

The OnDelete event moves the item from its current state to a deleted state. By default, the last state in your workflow process has an OnDelete action available.

On the workflow diagram, OnDelete is displayed with its friendly name, Delete. It is displayed as a transition from the state containing the OnDelete action to the ending block.

Order of events

  • OnExit Þ OnDelete

Entering and Exiting a State

The OnEnter and OnExit events are executed for each state transition.

Therefore, an OnEnter event is fired for inserts, and an OnExit event is fired for deletes. Both events are fired for each state transition.

Order of events

  • OnExit (current state) Þ OnTransition (to a new state) Þ OnEnter (next state)

Transition from One State to Another

The OnTransition event moves the item from its current state to the next state defined in the workflow process.

On the workflow diagram, the OnTransition is displayed as a connection from the current state to the next state.

Order of events

  • OnExit (current state) Þ OnTransition Þ OnEnter (next state)

Note   Changing only the state does not trigger a Change (OnUpdate) action. The data in the database must be modified for a Change action to occur.

Editing a Record

The OnUpdate event updates the database with any changes made to the data. By default, each workflow state has an OnUpdate event.

On the workflow diagram, the OnUpdate is displayed in the Actions****list with its friendly name, Edit.

Order of events

  • OnUpdate

Order of events if the update causes a state change

  • OnUpdate Þ  OnExit (current state) Þ OnTransition Þ OnEnter (next state)

Remaining in a State for a Certain Time

The OnTimeout event executes code after a designated amount of time has passed. The Microsoft SQL Server™ Agent manages the time and triggers the event by calling stored procedures on the server. For this reason, time-out events cannot work offline.

Each state can have multiple OnTimeout events. For example, you can define events that should occur at 30, 60, and 90 days.

Order of events if the time-out causes an update

  • OnTimeout Þ  OnUpdate

Order of events if the update causes a state change

  • OnTimeout Þ  OnUpdate Þ  OnExit (current state) Þ OnTransition Þ OnEnter (next state)

Example

Function State2_Validate_OnTimeout()
    If now - session.item("DateModified") >= 30 Then
        State2_Validate_OnTimeout = True
    End If
End Function

Sub State2_OnTimeout()
    session.item("statusDescription") = "Overdue"
    session.item.updatebatch
End Sub