Loop over Repeating Elements with a For-Each Action
The for-each action enables you to loop over a repeating element and process one or more actions within the scope of the for-each action. The number of loop iterations is based on a user-selected repeating element. For example, you may have an integration in which you download a number of files and want to loop over the output of the files. The for-each action enables you to perform this task.
Creating a For-Each Action
Note:
- You cannot use an unqualified repeating element in a for-each action.
- When you configure a stop action inside a for-each action, the entire integration is terminated when the for-each action is processed for the first time. The for-each action is not allowed to process more than once. The stop action does not display any message describing this behavior during design time.
-
Add a for-each action to an integration in either of the following ways:
- On the right side of the canvas, click
Actions
and drag the For Each action to the appropriate location.
- Click
at the location where you want to add the for-each action, then select For Each.
The Configure For Each panel opens. This includes a Sources tree of elements.
- On the right side of the canvas, click
Actions
-
Click Edit
under Configure For Each to enter a name and optional description for the for-each action.
-
Expand the Sources tree to select an element.
-
Drag a repeatable element to the Repeating Element field. This is the element over which to loop.
Note:
Note the following restrictions:-
The selected element must be repetitive. You can identify repetitive elements by the three-box icon to the left of the element name.
-
Any parent of the selected element must not be repetitive.
-
The data type of the selected element must be scalar.
-
Global and nonglobal repeated elements can be selected.
-
If you have a repeating element within another repeating element (that is, a list within a list), you must first create a for-each action and loop over the parent list. This gives you access to the child list during every iteration. You can then create a second for-each action within the scope of the first for-each action and loop over the child list.
For this example, the element over which to loop is ICSFile.
For every iteration of the loop, there is a single reference to the repeating element (ICSFile). A current element name file is required for this action to occur.
-
-
Enter an alias for the current file of the iteration in the Current Element Name field.
Note:
If you drag a for-each action into a schedule integration, an additional field called Process items in parallel is visible at the bottom of the dialog.When selected, iterations of the for-each action are run in parallel. For example, if an integration processes a list of files with a for-each loop created over every file, the processing of the entire file is done in parallel for every file. If a variable is declared outside a for-each loop with Process items in parallel selected and updated within the for-each loop, the last updated value for that variable is available outside of the loop. Also, the degree of parallelism (DOP) is set to
1
to avoid concurrency issues. -
Click Save.
The for-each action is displayed in the canvas. A looping arrow indicates that this action performs repetitive looping.
-
Click + inside the for-each action to add additional actions. These actions define what happens during each iteration of the loop. For this example, scope and switch actions are defined within the for-each action.
Using Global Variables in For-Each Loops
When global variables are used in for-each loops (for example, for logging purposes), they can lead to the following runtime exception when bad or invalid data is associated with the variable:
FORG0001: invalid value for cast/constructor, Cikey=13695578,
FlowId=10025204, Current Activity Key=13695578-BpAss43-BpSeq8.240-4, Current
Activity Label=assignment_ics_api_internal_variable23,
As a recommendation:
-
Limit the use of global variables in for-each loops.
-
Global variable handling requires database access, which results in an added performance overhead.
-
Local variables can be used for logic specific to a local scope.
Tracking the Status of a For-Each Action During Runtime
You can track the status of the for-each action on the Instances page through the tracking diagram and activity stream for an activated integration.
- In the navigation pane, click Observability, then Instances.
-
Click the business identifier value of the integration to track.
The integration flow (including any for-each actions) is displayed. Any for-each action failures are identified by red arrows. The activity stream is displayed on the right side.
- Use Bulk Response Operations in an Integration in Using the Salesforce Adapter with Oracle Integration 3
- Process Large Data Sets Asynchronously with Different Bulk Import Operations in Using the Marketo Adapter with Oracle Integration 3
- Subscribe to Atom Feeds in a Schedule Integration in Using the Oracle HCM Cloud Adapter with Oracle Integration 3
- Invoke an Endpoint Dynamically in Using the Oracle ERP Cloud Adapter with Oracle Integration 3
- Create an Integration to Import and Process Bulk Files in Using the FTP Adapter with Oracle Integration 3