Workflow Scripting
The built-in functionality of workflow events can be enhanced using Microsoft® Visual Basic® Scripting Edition (VBScript). Scripts associated with a workflow events are entered on the Script Editor.
A single transition, such as moving from one state to another, can trigger several different events that must occur in a particular sequence. You can control the flow of your script with conditional statements and looping statements. Using conditional statements, you can write Microsoft® Visual Basic® Scripting Edition (VBScript) code that makes decisions and repeats actions.
For each event in your workflow process, you can specify a conditional statement to evaluate whether a condition is True or False and, depending on the result, to specify one or more statements to run. Usually, the condition is an expression that uses a comparison operator to compare one value or variable with another.
For instance, if you must validate that a certain user was updating an item, you could write a function that evaluates the sender property of the WorkflowSession object. If this function returns True, then the event script procedure is fired.
Sales Tracking Scenario
You have a sales tracking workflow process, and you want to notify the stock room when an order is marked as completed. You can use script on the Change event to evaluate the contents of the completed field. When this field is set to Yes to indicate the order is completed, an event script procedure that sends a message to the stock room is triggered. If the condition returns False, the event is stopped, and the event script is not executed.
The following illustration shows a state called Active that has a Change event used to create a transition to a state called Resolved. When an item in the folder is changed, the condition is evaluated. If the condition is set to False or if a function called by the statement returns False, the transition does not occur, and the event script associated with Change — in this case, a call to a procedure called SendMail — is not executed.
Change Event
In many applications, particularly document-approval applications, you might want to make it possible for editing updates that do not advance the workflow state. In such a case, you can add a Transition-Within Change event.
For example, the following illustration portrays a portion of an order entry workflow process. As an order is updated, the Change event is triggered many times before the order is filled. A Change event called UpdateItem has been added to the OrderCompleted state (shown on the left). There is another Change event on this state called CompleteOrder (shown on the right).
The CompleteOrder event calls a function that evaluates a field called OrderCompleted. Each time the order is updated, both change events are triggered. However, the CompleteOrder transition does not occur until the OrderCompleted field is set to True by the user.
Multiple Change Events
Note The CheckOrder function shown in the illustration is not complete syntactically.
See Also
Workflow Applications Architecture for Exchange Server | Workflow Applications | Exchange Server and Public Folders | Application User Interface | Planning a Workflow Process | Scripting in the Workflow Designer | Order of Workflow Events