Creating a For Each Loop

At runtime, each occurrence of the selected data, such as a repeating element for order items, is processed one at a time until all instances in the data are evaluated. At that time, the loop terminates and process flow control continues along the path connected to the output terminal of the loop.

To create a For Each loop for automatic processing:

  1. Create a loop in the business process.

  2. Open the Loop complex activity and add the activities to be performed in the loop.

Note: To enable breaking out of the loop before completion of all processing, place the Break activity at the location in the flow where the break should occur (generally the False path for a rule).

  1. Close the loop and edit the properties of the loop based on the following information:

Property

Description

Loop Type

Selection of type of loop.

Counter Context Reference

Optional identification of the context variable that is incremented after each iteration in the loop.

Current Item Context Reference

The context reference that serves as the container for each instance of data during the iteration process.

Selection Expression

Reference to the context variable that specifies the repeating (unbounded) data that is iterated in the loop.

 

  1. Select the Loop Type property For Each in the drop-down list.

  2. Identify the Selection Expression property to indicate the repeating data to be processed.  Click in the value column for the Selection Expression property. Click and select the context variable that specifies the schema for the iterating data.

Note: This requires that you created a context variable with a Complex data type with a schema specified. This context is typically autogenerated, which is used as the target property of a notification iface or a map.. See Adding Context Variables.

  1. In the Content Model column on the Set Context References, select the repeating element. In the schema, this is: (maxOccurs=unbounded)

  2. Identify the Current Item Context Reference property to provide the runtime engine with the ability to store and process each instance as it is captured.

This container will be reused for the processing on each instance of the data. The information is not retained in this container for later use in the business process.

Click in the value column for the Current Item Context Reference property. Click and select the context variable that specifies the container for each instance as it is processed.  In the Content Model column on the Set Context References, select the parent element of the repeating element specified in the selection expression.

Note: You cannot use the same context variable for the selection expression and current item context reference. This requires that you  manually created a context variable with a Complex data type of and specified the same schema as used by the context variable used for the selection expression. See  Adding Context Variables.

  1. To keep count of the number of instances processed in the iteration for later use in the business process, specify the Counter Context Reference you are using to store the number of iterations processed in the loop.

Click in the value column for the Counter Context Reference property. Click and select the context variable.

Note: Using the Counter Context Reference requires that you created a context variable with an integer data type to retain the number of iterations. See Adding Context Variables.

Example