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:
- Normal--A
normal branch has a condition associated with it; if that condition
is met, the branch is taken. You can have multiple normal branches.
By default, normal branches are represented by a blue square.
- Exception--An
exception branch has a specific exception type associated with it. The
condition of an exception branch tests that the system variable currentException
is equal to the exception type to which you set the branch. You can
have multiple exception branches. By default, exception branches
are represented by a red square.
- Default--The
default branch is taken when none of the other branch conditions are
true. Each decision node can have one (and only one) default branch.
This branch is optional. By default, it is represented by a black
square.
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
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
Perform the following steps to
add a decision node to your activity diagram:
- 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.
- Click the Decision Node button in the Symbols toolbar.
- 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.
- 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:
- In the diagram editor, double-click the decision node symbol.
The Decision Properties dialog box opens.
- 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.
- 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
- 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).
- 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.
- 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.)
- Click Ok to close the Condition Editor and return to the Decision
Properties dialog box.
- Optionally, type a label for the branch in the Branch Label
table cell. Labeling your branches can improve the readability of
your activity diagram.
- Optionally, type a description for the branch in the Comment
table cell.
- 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:
- In the diagram editor, double-click the decision node symbol.
The Decision Properties dialog box opens.
- 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.
- Click the table cell in the Condition column and select the
type of exception from the drop-down list of exception types.
- Optionally, type a label for the branch in the Branch Label
table cell. Labeling your branches can improve the readability of
your activity diagram.
- Optionally, type a description for the branch in the Comment
table cell.
- 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:
- In the diagram editor, double-click the decision node symbol.
The Decision Properties dialog box opens.
- 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.
- Optionally, type a label for the branch in the Branch Label
table cell. Labeling your branches can improve the readability of
your activity diagram.
- Optionally, type a description for the branch in the Comment
table cell.
- 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
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 Express 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:
- In the diagram editor, locate the decision node whose branches
you want to swap.
- Click the transition link for one of the branches you want to
swap.
- While holding down the Alt key, drag the top of the transition
link from its original branch to the new branch.
- Release the Alt key. Process Designer Express swaps
the two transition links and their associated conditions and updates
the list of branches in the Decision Properties dialog box.
