Decision nodes

If you want one action to flow to the next regardless of conditions, a transition link is all that is necessary. If, however, you want to branch to more than one action based on a set of conditions, you need to include a decision node. In its most common usage, a decision node connects an action to all of its possible outcomes, including other actions, subdiagrams, and end symbols. Decision nodes can be used with the action, subdiagram, and iterator nodes. Do not place a decision node directly after a start symbol.

A decision node typically has at least two branches; the maximum number of branches is seven. Each branch has a condition associated with it that determines whether that branch is taken or not.

Important

When implementing a decision node, ensure that you define the conditions such that there will always be one that evaluates to true. If none of the conditions in your decision node evaluate to true, a runtime error occurs.

There are three types of branches in a decision node:

These branches are defined and their conditions set in the Decision Properties dialog box, as shown in Figure 40.

Figure 40. Decision Properties dialog box

The figure shows the decision properties dialog. The top area is a scrollable selection list that displays the decision label. The next area is a scrollable text box for the description. The next area displays all the possible decision points by diagramming those points on the diamond and allows you to enter the appropriate information in the following fields: type, condition, branch label and comment. Below the decision entry area is an apply button, a discard button and a close button.

Each defined branch of a decision node must have a transition link that connects it to its associated outcome (for example, an action node or a end symbol).

Figure 41 illustrates a sample activity diagram with a decision node. In this example, the decision node has three branches. The normal branch shifts the flow to Action 2 if its condition evaluates to true. The exception branch shifts the flow to End Failure if a JavaException exception is thrown. The default branch shifts the flow to Action 3 if the condition of the normal branch evaluates to false and a JavaException is not encountered.

Figure 41. Activity diagram with a decision node

The figure shows an activity diagram. At the top is action 1 which leads into a decision block with 3 paths. One branch is for value is provided path and leads to action 2. The second branch is for the no value provided (default) path and leads to action 3. The last branch is the JavaException path and leads the end failure node.

Perform the following steps to add a decision node to your activity diagram:

  1. Ensure the diagram editor is open, and that you have already placed the symbol that is going to flow to the decision node. Decision nodes can be used by any action, subdiagram, or iterator node.
  2. Click the Decision Node button in the Symbols toolbar.
  3. In the diagram, position your cursor underneath the symbol that is going to use the decision node, and then click to place the node in the diagram.
  4. Create a transition link between the decision node and the symbol that calls it. See Creating a transition link for more information on creating transition links.

Defining a normal branch

Each normal branch requires a condition. These conditions are created with variables that you define in the collaboration template or the scenario. Before you can create a normal branch, you must define the necessary variable for the condition. See Declaring and editing template variables (the Declarations tab) and Defining scenario variables for more information.

Perform the following steps to define a normal branch in a decision node:

  1. In the diagram editor, double-click the decision node symbol. The Decision Properties dialog box opens.
  2. In the row for the branch you are creating, click the table cell in the Type column and select Normal from the drop-down list of branch types.
  3. Right-click the table cell in the Condition column and select Condition Builder from the context menu.
    Note:
    You can also type the condition directly into the Condition table cell instead of using the Condition Editor.
    The Condition Editor dialog box is displayed.

    Figure 42. Condition Editor

    The figure shows the condition editor dialog. The top area is a drop-down selection list for the variable name. The next area is a text display field for data type. Underneath that field is a drop-down selection list for operator. Underneath the operator list is a condition entry field. At the bottom of the dialog is an ok button and a cancel button.

  4. In the Variable Name field, use the drop-down list to select the variable you want to evaluate for the condition. This list contains all of the collaboration variables you have defined for the scenario.

    When you select a variable, the Data type field is automatically updated to include the variable type (for example, Boolean or String).

  5. In the Operator field, use the drop-down list to select the appropriate operator to use for evaluating the variable. The list contains only those operators supported by the type of variable you are using.
  6. In the Condition field, enter the value you want to use for the condition. (For example, if you have a Boolean variable named hasValue, you can set the condition to either true or false.)
  7. Click Ok to close the Condition Editor and return to the Decision Properties dialog box.
  8. Optionally, type a label for the branch in the Branch Label table cell. Labeling your branches can improve the readability of your activity diagram.
  9. Optionally, type a description for the branch in the Comment table cell.
  10. Click Apply to add the branch to the decision node. In the activity diagram, the decision node now contains a blue square to indicate the normal branch you just created.

After you add a normal branch, you must connect it to its associated result with a transition link.

Defining an exception branch

Perform the following steps to define an exception branch in a decision node:

  1. In the diagram editor, double-click the decision node symbol. The Decision Properties dialog box opens.
  2. In the row for the branch you are creating, click the table cell in the Type column and select Exception from the drop-down list of branch types.
  3. Click the table cell in the Condition column and select the type of exception from the drop-down list of exception types.
  4. Optionally, type a label for the branch in the Branch Label table cell. Labeling your branches can improve the readability of your activity diagram.
  5. Optionally, type a description for the branch in the Comment table cell.
  6. Click Apply to add the branch to the decision node. In the activity diagram, the decision node now contains a red square to indicate the exception branch you just created.

After you add an exception branch, you must connect it to its associated result with a transition link.

Defining a default branch

Each decision node can have only one default branch. Adding a default branch is optional.

Perform the following steps to add a default branch to your decision node:

  1. In the diagram editor, double-click the decision node symbol. The Decision Properties dialog box opens.
  2. In the row for the branch you are creating, click the table cell in the Type column and select Default from the drop-down list of branch types.
  3. Optionally, type a label for the branch in the Branch Label table cell. Labeling your branches can improve the readability of your activity diagram.
  4. Optionally, type a description for the branch in the Comment table cell.
  5. Click Apply to add the branch to the decision node. In the activity diagram, the decision node now contains a black square to indicate the default branch you just created.

Note that you cannot specify a condition for the default branch. The condition is implicit; it evaluates to true when all of the conditions associated with the other branches evaluate to false.

After you add the default branch, you must connect it to its associated result with a transition link.

Combining an exception and a condition in branching logic

A branch can be normal or an exception, but not both. However, there are times when you might want to specify the execution path to take in response to two simultaneous conditions: an exception occurred and another condition is true. This combination is the equivalent of using an AND operator in a conditional expression.

For example, suppose you want to model these two conditions:

Exception == JavaException && hasValue == false
Exception == JavaException && hasValue == true 

To model such a construct, create two levels of decision nodes, putting an action node between them, as shown below:

Figure 43. Combining an exception and a condition

The figure shows Action 1 leading into decision 1. One branch of the decision is the default branch and leads to action 2. The other branch of the decision is JavaException and leads to Action 3. Action 3 flows into decision 2. One branch of decision 2 is the no value provided path and drops into an end failure node. The other branch flows into action 4.

Swapping decision node branches

You can swap branches in a decision node by essentially dragging and dropping the branches in the activity diagram. Process Designer automatically updates the Decision Properties dialog box to reflect the new location of each branch.

Perform the following steps to swap the location of two branches in a decision node:

  1. In the diagram editor, locate the decision node whose branches you want to swap.
  2. Click the transition link for one of the branches you want to swap.
  3. While holding down the Alt key, drag the top of the transition link from its original branch to the new branch.
  4. Release the Alt key. Process Designer swaps the two transition links and their associated conditions and updates the list of branches in the Decision Properties dialog box.

Copyright IBM Corp. 1997, 2004