Branching

The choice activity makes it possible to model process branching. To model process branching, the process must evaluate one or more rules to reach a decision, and then specify which activity to run as a result of that decision.

  • The choice activity must include the select element.
  • The select element must include one or more case elements.
  • Each case element links the outcome of a rule to a child activity. The activity attribute in the case element identifies the child activity to run.
  • Each case element has a ref attribute, which contains the name of a rule that is defined at the top of the process. Case elements refer to rules instead of conditions because:
    • A rule can contain more than one condition. If a rule element contains more than one condition, all the conditions in the rule must be true in order for the rule to be true.
    • A condition is a single entity within a rule.
  • If the rule is true, the activity runs.
  • If the rule is false when the negative attribute is true, the activity runs.
  • Multiple cases can reference the same activity. However, the activity runs only once.
  • If an activity is not referenced, it does not run.
  • If no activity runs, the choice activity completes immediately.
  • Use a choice element with a simple activity to model a deferred activity.
  • Priorities and defaults are modeled through rule dependencies, not through the order of the case elements.

When the business process runs the choice activity, Sterling B2B Integrator checks the case statements in the order that they are listed in the select element. These statements are evaluated one by one as OR statements (not AND), similar to a common switch structure. The first statement to evaluate to true is the one that executes. At that point the case statement short circuits and completes execution. The system does not continue to evaluate further case statements.

For example, the first case statement in the select element determines whether the rule is true. If the rule is true, the activity named by the activity attribute is executed immediately. When that activity completes, the choice activity is complete. If the second case statement in the select element refers to the same rule as the first but has a negative attribute set to true, then the case statement executes the named activity if the rule is false.

In the online bookseller example discussed in previous sections, the Process Customer Book Order process verifies a customer's credit card only if the book the customer selects to buy is in stock. The BookInStock rule is true if the book is in stock and false if the book is out of stock.

If the inventory system determines that the book is in stock, the rule referred to in the case statement is true and the proceed activity is run.


<process name="ProcessCustomerOrder">
   <rule name="BookInStock">
      <condition>foundBook = true </condition>
   </rule>

   <sequence>
      <operation name='Check Inventory'>
         <participant name='InventoryService' />
         <output message='checkStockRequest'>
            <assign to='ISBN'>1-56592-488-6</assign>
         </output>
         <input message name='checkStockResponse'>
            <assign to='foundBook' from='InStock' />
         </input>
      </operation>

      <choice>
         <select>
            <case ref="BookInStock" activity="proceed"/>
            <case ref="BookInStock" negative="true" activity="stop"/>
   </select>

         <sequence name="proceed">
            <operation name='Verify Credit Card'> … </operation>
            …
         </sequence>

         <sequence name="stop">
            <operation name='Apologize to Customer'> … </operation>
         </sequence>
      </choice> 

      <operation name='Update customer on status'> … </operation>
   </sequence>
</process>