Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 6 Controlling Flow : Using Loops

Using Loops
TIBCO Business Studio supports standard and multi-instance loops as defined in BPMN.
Standard loop  A standard loop consists of a Boolean expression that is evaluated either before (loop while condition is true) or after (loop until condition is true) each cycle of the loop.
Multi-instance loop  A multi-instance loop has an expression that evaluates to an integer, and is evaluated only once (before the activity is performed). The resulting integer specifies the number of times the activity should be performed.
You can select the type of loop applied to a task either in the Properties view for that task (on the General tab), or by right-clicking the task and selecting from the Activity Markers menu. The Loops tab in the Properties view for the task is where you specify the details of the loop.
This section describes how to create loops in TIBCO Business Studio, and how to implement the supported BPMN patterns.
Creating a Standard Loop
A standard loop is indicated by the following symbol:
Click the Loops tab to set the details of the loop:
 
Set the following parameters as appropriate for the loop you want to create:
Test Time  Select either Before or After. The Before option is equivalent to the programming construct "while": the expression is evaluated before the activity is performed, and therefore if the expression evaluates to False, the activity is not performed. The After option corresponds to the programming construct "Do: while": the expression is evaluated after the activity has been performed, guaranteeing that the activity is performed at least once.
Loop Maximum  Optionally specify an integer to control the maximum number of times the activity is performed. In the event of conflict between Loop Maximum and the result of the Javascript defined under Script Defined As, the Loop Maximum will override the script calculation.
Script Defined As  Select one of the following options:
Free Text  Allows you to describe how you would like the loop to be tested if you prefer to leave the specific implementation of the loop expression to someone else.
JavaScript  Allows you to enter JavaScript that will be evaluated for the loop expression.
Unspecified  Allows you to specify that there is no expression or description for this loop.
Creating a Multi-Instance Loop
A parallel multi-instance loop is indicated by the following symbol (a sequential multi-instance loop uses the standard symbol):
Click the Loops tab to set the details of the loop:
 
Set the following parameters as appropriate for the loop you want to create:
Ordering
Select either Sequential or Parallel. The Sequential option causes the instances of the activity to occur in succession rather than at the same time. The Parallel option causes the instances of the activity to occur at the same time.
Flow Condition
This property can be used to mimic the functions of a gateway. Select one of the following options:
All (perform outgoing flow when all instances complete)  The outgoing flow is processed once after all activity instances have completed.
One (perform outgoing flow once when first instance completes)  The outgoing flow is processed when the first activity instance completes (existing instances can still be completed but the outgoing flow is not processed when they complete).
No Condition (perform outgoing flow for each completed instance)  The outgoing flow is processed for every activity instance as it completes.
Complex (behavior defined by Complex Flow Condition)  The outgoing flow is processed for each instance for which the Complex Flow Condition tab evaluates to true.
Scripts for Multi-Instance
Select Free Text for the Script Defined As field if you want to describe how you would like the loop to be tested, and prefer to leave the specific implementation of the loop expression to someone else. You can also select Unspecified if there is currently no condition or description for the loop.
Depending on the destination environment you have selected, JavaScript may be available as an option. Use this option if you want to enter JavaScript that will be evaluated for the loop expression.
There are three tabs on which you can specify scripts:
Loop Expression  Specify either a script that evaluates to an integer or a description of the desired script.
Complex Flow Condition  This expression is evaluated if you selected Complex as the Flow Condition.
Additional Instances Expression  This expression is used for control-flow pattern WCP-15 (additional activity instances may be required at runtime) when you only need to add instances when the task is complete. See the table "Supported Control Flow Patterns" in the "Workflow Patterns Reference" appendix of the TIBCO ActiveMatrix BPM - BPM Concepts guide. If you need to add instances while the task is in progress, see Adding Additional Instances to a Multi-Instance Loop Task Whilst the Task is in Progress.
The additional instances script is evaluated after the last instance completes. If the script evaluation calls for additional instances, they will be done and the script will be evaluated again once the last additional instance completes.
Adding Additional Instances to a Multi-Instance Loop Task Whilst the Task is in Progress
You can add additional instances to a multi-instance loop while the task is still in progress. This implements control-flow pattern WCP-15—see the table "Supported Control Flow Patterns" in the "Workflow Patterns Reference" appendix of the TIBCO ActiveMatrix BPM - BPM Concepts guide.
To do this, you need to execute a script somewhere on a parallel path whilst the loop task is active. The script can add instances to the loop task using an expression similar to the following:
Process.addActivityLoopAdditionalInstances ("OrderStock",1);
which contains a string for the name of the task (in this example, OrderStock), and an integer for the number of additional instances required (in this example, 1)..
You can also add additional instances to a loop in the loop task itself, but only in the task Complete script.
In this example, the task Add parts to order would order an additional item each time it was used.
Example - Multiple Instances with Synchronization (WCP-13)
This workflow pattern specifies that multiple instances of an activity should be created, each instance being synchronized and able to run concurrently. See the table “Supported Control Flow Patterns” in the “Workflow Patterns Reference” appendix of the TIBCO ActiveMatrix BPM - BPM Concepts guide. Note that:
The following process has three activities:
There can be multiple instances of the Each Direct Debit task. This is indicated on the General tab of the Properties view:
The details are specified on the Loops tab:
The Parallel ordering setting and All flow condition means that the activity instances will be performed at the same time and will be synchronized. The number of instances is set to 3 on the right side of the Properties view.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved