Table of Contents


  1. Preface
  2. Part 1: Using Process Developer
  3. Part 2: Creating and Modifying Processes
  4. Part 3: Functions, Events, Errors, and Correlation
  5. Part 4: Testing and Deployment
  6. Part 5: Process Central and Process Server (On-Premises)

Process Developer

Process Developer

For Each

For Each

BPMN Implementation: Multi-Instance control flow
The For Each activity contains a scope activity and executes it for a specified count. The execution iterations can occur in parallel or in sequence. The number of iterations to execute is determined by evaluating expressions for a start and final value. These values are inclusive, so a start of one and a final of 10 causes the enclosed scope to execute 10 times.
The expressions for the start and final values must evaluate to an
. If it doesn't, a runtime exception of
occurs. If the final value is greater than the start value then the for each will not execute.
The counter name of the For Each is manifested as an implicit variable within the child scope. The initial value of the variable is set to the current value of the For Each's iteration, which ranges from the start value to the final value. This variable is accessible to all activities nested within the For Each's scope and appears as a variable within the child scope.

Using a Completion Condition for Processing N of M Branches

A For Each activity can include an optional
Completion Condition Expression
property that can in turn include an optional
Count Successful Branches Only
The completion condition expression can be used to process at least N out of M branches. The expression evaluates to an
value that is used to define condition of N out of M. It is evaluated once, when the for each begins its execution. If the
is not an
, or it is determined that it cannot be met prior to executing, the For Each faults with a
. An example of this would be a
value of five when there are only three iterations of the for each.
The property
Count Successful Branches Only
can be set to Yes or No. If set to
, it means the Process Developer engine counts branches towards it completion condition that have completed normally (meaning the child scope of the for each iteration did not catch a fault and is eligible for compensation). The default value of No results in the For Each counting the completion of any child iteration towards its completion condition.
At the completion of each iteration, the For Each tests the number of completed scopes versus its completion condition (taking into account the Count Successful Branches Only setting as described above). If it there are not enough iterations remaining to fulfill its completion condition, the For Each faults with a
and any remaining iterations do not execute, or are terminated in the case of the parallel for each.
A common use of the completion condition is to process only the minimum number of items necessary to complete a scope of work. For example, a BPEL process can call out to many partners in parallel, asking for approvals on an item. The process can require that only three approvals be needed to continue processing the item. Even though the process requested many approvals, it can break off the approval scope of work when only three approvals are received. It can then continue with further processing.

Parallel For Each

You can create a parallel or sequential For Each. In a parallel For Each, instances of the enclosed activity occur simultaneously. Each counter variable is initialized to one of the integer values in the count.
Use a parallel For Each for simultaneous processing of document parts. For example, you can process parts of a complex message variable, such as line items in a purchase order.
A default Message Exchange property that keeps together the correct pair of receive/replies or onMessage/replies, is automatically and implicitly declared in the scope. For details, see Message Exchange Declaration.

Sequential For Each

In a sequential For Each, instances of the enclosed activity execute one at a time.
Required Properties
Optional Properties
Counter Name
Start Counter Value
Completion Condition Expression
Final Counter Value
Count Successful Branches Only
Parallel Execution Flag
Suppress Join Failure. See Process Properties
Extension Attributes and Extension Elements. See Declaring Extension Elements and Attributes.

To build a For Each

  1. From the
    Control Flow
    palette, drag a
    activity to the Process Editor canvas.
  2. In the Properties view of the For Each, fill in the required properties:
    • Parallel Execution Flag. Enable this setting to execute all instances of the activity concurrently. Be sure to read the Parallel For Each discussion above to learn the requirements for this type of execution. Disable this setting to execute the scope's activities sequentially.
    • Add a Counter Name that identifies the enclosed scope's local variable. The default name is counter.
    • Start Counter Value. Add an unsigned integer for the value. Type in a value or select the
      Dialog (...) Button
      at the end of the row to open the Expression Builder. For details, see Using the Expression Builder.
    • Final Counter Value. See Start Counter Value above.
    • If desired, add values for the optional property Completion Condition
      and enable Count Successful Branches to count only successful branches, as described above.
  3. Fill in the properties for the Scope container.
  4. Specify all the properties for each activity in the scope container. Be sure to set a message exchange property for matching receive/replies and
    /replies within the scope if parallel execution is enabled.

XML Syntax

<forEach counterName="NCName" parallel="yes|no"> standard-attributes> standard-elements <startCounterValue expressionLanguage="anyURI"> </startCounterValue> <finalCounterValue expressionLanguage="anyURI"> </finalCounterValue> <completionCondition extension-attribute extension-element <branches expressionLanguage="URI"? countSuccessfulBranchesOnly="yes|no"?> an-integer-expression </branches> </completionCondition> activity </forEach>
Example 1: 100 Executions, Executing if 10 Succeed
<forEach counterName="counter" parallel="no"> <startCounterValue>1</startCounterValue> <finalCounterValue>100</finalCounterValue> <completionCondition> <branches countSuccessfulBranchesOnly="yes"> 10</branches> </completionCondition> <scope>...</scope> </forEach>
Example 2: Serial For Each with Completion Condition
Example 3: Execution Thread of a Parallel For Each Activity
The following illustration shows the execution thread of a parallel For Each that has a counter value of 10. Notice that 10 instances of the enclosed scope are running in parallel.

Faults Associated with a For Each Activity

The following faults can occur with a For Each activity:
  • If a running process encounters an error with the counter variable, it throws a
  • In a For Each activity, if a completion condition can never be true, the
    is thrown.
  • If the integer value evaluated from the Count Completed Branches Only expression is larger than the Counter, the
    fault is thrown.


We’d like to hear from you!