Conditional Workflow Tickets

By default, workflow executes subordinate business services sequentially. Conditional workflow allows for altering the sequence of execution by using “flow control” statements. Flow control statements are at the same level as business services. Both are considered “work steps” in conditional workflow. Flow control statements currently supported are:

  • continue - “Fall through” and execute the next work step (which may be a business service or another flow control statement). The absence of a flow control statement following a business service implies “continue”.
  • end - Terminate execution of the workflow. In the ‘end’ step you may specify an ‘end-code’ attribute which is either ‘0’ (default) or ‘1’. A '1' indicates that if the workflow completes successfully then the job record will be deleted from the database. This is useful for workflows that are looking for work to perform. However, if no work is found, they can keep the database from filling up with jobs that did not work.
  • goto - Jump to the specified work step (which may be a business service or another flow control statement). The step to go to is identified by an XPath expression.
  • if - Evaluates an expression and, if true, executes a statement that must be a “continue”, “goto”, or “end” statement. If the “if” statement is false then the next work flow statement or business service is executed (if any). Multiple “if” statements may be specified. The “if” statement currently supports simple expressions only. No compound and nested expressions are supported. Expressions may contain variables that are named values whose values are resolved at execution time by XPath queries.

The following is an example of how conditional workflow could be used in a job ticket. This example gets the price of Microsoft stock and then makes the decision to buy or sell based on price.

<workflow>
<stockquote>
<request tag="request1" name="get-price">
<symbol>MSFT</symbol>
</request>
</stockquote>
<flow-control>
<variable name="PRICE" from="stockquote/request[@tag='request1']/price"/>
<if expression="PRICE < 20">
<goto>stocktrader [@tag=buy']</goto>
</if>
<if expression="PRICE > 30">
<goto>stocktrader[@tag=sell']</goto>
</if>
<end/>
</flow-control>
<stocktrader tag="buy">
<request name="buy">
<symbol>MSFT</symbol>
<shares>100</shares>
</request>
</stocktrader>
<flow-control>
<end/>
</flow-control>
<stocktrader tag="sell" >
<request name="sell">
<symbol>MSFT</symbol>
<shares>100</shares>
</request>
</stocktrader >
</workflow>

The above job ticket will first get the price of a share of Microsoft stock from the “stockquote” business service. If the price is less than $20 then 100 shares are purchased from the “stocktrader” business service. If the price is greater than $30 then 100 shares are bought. Otherwise nothing is done.

The first “flow-control” statement declares a variable named “PRICE” and specifies that its value (using an XPath query in the “from” attribute) is to come from the “price” output parameter of the “stockquote” business service. Once a variable is defined then it can be used in a subsequent “if” statement. The first “if” statement evaluates the price and compares it to $20. If true then the “goto” is executed. In this case the jump is to the work step that is the “stocktrader” business service request to buy 100 shares. The “go to” location is defined by the appropriate XPath query that must resolve to a valid work step (i.e., a business service or a “flow-control” statement). The next “if” statement determines if the price is greater than $30 and, if so, 100 shares are sold. Otherwise the workflow is terminated by the “end” statement.