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:
For more information about scripting workflow events, see Scripting Workflow Actions.
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.
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.
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.
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.
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.
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.
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.
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