For Each Loop in OIC Explained
For Each Loop in OIC Explained: A Complete Guide with Examples
When working with Oracle Integration Cloud (OIC), integrations frequently need to process multiple records, files, employees, invoices, orders, or other repeating data. Processing each item individually is a common requirement in real-world integration scenarios.
This is where the For Each action in Oracle Integration Cloud becomes extremely useful.
The For Each action allows you to iterate over a repeating element and execute one or more actions for every item in that collection. Oracle’s documentation describes it as a looping mechanism where the number of iterations is determined by the selected repeating element.
In this guide from Learnomate Technologies, we will understand what the For Each loop is, how it works in OIC, how to configure it, practical examples, nested loops, parallel processing, common mistakes, and best practices.
What Is a For Each Loop in OIC?
The For Each action in OIC is used when an integration receives a collection of repeating elements and you want to process each element individually.
For example, suppose an API returns 100 employees:
Employee 1
Employee 2
Employee 3
...
Employee 100
If you need to call another API for every employee, you can use a For Each action instead of creating separate actions for every employee.
Conceptually, the integration works like this:
Input Collection
|
v
For Each
|
+---- Employee 1 → Process
|
+---- Employee 2 → Process
|
+---- Employee 3 → Process
|
+---- Employee N → Process
The loop automatically executes the actions placed inside its scope for each occurrence of the selected repeating element.
Why Do We Need For Each in OIC?
Modern integrations commonly deal with bulk data.
For example:
- Multiple employees from Oracle HCM
- Multiple invoices from Oracle ERP
- Multiple sales orders
- Multiple customer records
- Multiple files from an FTP server
- Multiple rows from a CSV file
- Multiple records returned by a REST API
- Multiple order lines
Without a loop, you would need to design repetitive processing logic manually.
With For Each, the same logic can be applied dynamically to every record.
Example
Suppose an API returns:
{
"employees": [
{
"id": "101",
"name": "John"
},
{
"id": "102",
"name": "Sara"
},
{
"id": "103",
"name": "David"
}
]
}
The employees element is repeating.
You can configure:
Repeating Element = employees
Current Element Name = employee
OIC then processes:
employee → John
employee → Sara
employee → David
Key Components of a For Each Action
When configuring a For Each action, there are several important fields to understand.
1. Repeating Element
The Repeating Element defines the collection over which OIC should iterate.
For example:
employees
or:
orders
or:
File
The selected element must be repetitive. Oracle identifies repeating elements in the source tree using the appropriate repeating-element indicator.
2. Current Element Name
The Current Element Name is an alias used to reference the individual item being processed during the current iteration.
For example:
Repeating Element: employees
Current Element Name: employee
During each iteration, employee represents the current employee record.
Conceptually:
Iteration 1 → employee = John
Iteration 2 → employee = Sara
Iteration 3 → employee = David
Oracle requires a current-element name so that the individual repeating element can be referenced inside the For Each scope.
3. Actions Inside the Loop
After creating the For Each action, you can add actions inside its scope.
For example:
For Each Employee
|
+--- Assign
|
+--- Switch
|
+--- REST Invoke
|
+--- Logger
These actions are executed for each iteration.
Oracle documentation notes that additional actions can be added inside the For Each action to define what happens during every iteration.
How to Create a For Each Loop in OIC
Let’s understand the process using an employee-processing example.
Step 1: Create an Integration
Log in to your Oracle Integration instance.
Navigate to:
Home → Integrations → Create
Create an appropriate integration, such as an App Driven Orchestration.
For example:
Integration Name: Process Employees
Identifier: PROCESS_EMPLOYEES
Step 2: Configure the Trigger
Assume the REST trigger receives the following payload:
{
"employees": [
{
"employeeId": "101",
"employeeName": "John",
"department": "IT"
},
{
"employeeId": "102",
"employeeName": "Sara",
"department": "HR"
},
{
"employeeId": "103",
"employeeName": "David",
"department": "Finance"
}
]
}
Here:
employees[]
is the repeating element.
Step 3: Add the For Each Action
From the Actions palette, select:
For Each
Drag it onto the integration canvas.
Oracle provides the For Each action as an integration logic action for looping over repeating elements.
Step 4: Configure the Repeating Element
Open the For Each configuration.
From the source tree, locate:
employees
Drag the repeating employees element into:
Repeating Element
Then provide:
Current Element Name:
employee
For example:
| Field | Value |
|---|---|
| Name | ProcessEmployees |
| Repeating Element | employees |
| Current Element Name | employee |
Step 5: Add Actions Inside the Loop
Click the + inside the For Each action.
You can now add actions that should execute for every employee.
For example:
For Each Employee
|
+--- Assign
|
+--- REST Invoke
|
+--- Logger
If there are three employees, the actions execute three times.
Practical Example: Process Employee Records
Let’s consider a real-world integration.
Requirement
An HR system sends employee information to OIC.
For every employee:
- Read employee ID.
- Call another REST API.
- Update employee information.
- Log the result.
The integration could look like:
REST Trigger
|
v
For Each Employee
|
+---- Assign Employee ID
|
+---- REST Invoke
|
+---- Logger
|
v
Response
If the source contains 500 employees, the same processing logic can be applied to each employee.
For Each with FTP Files
For Each is also useful when working with files.
For example, suppose an FTP operation returns multiple files:
Employee_01.csv
Employee_02.csv
Employee_03.csv
Employee_04.csv
You can use a For Each action to process each file.
The flow could be:
FTP List Files
|
v
For Each File
|
+--- Download File
|
+--- Stage File
|
+--- Read File
|
+--- Process Records
Oracle provides examples of using For Each to iterate through individual files returned from file operations.
For Each for CSV File Records
Another common scenario is processing individual rows from a CSV file.
Suppose a CSV contains:
Employee_ID,Employee_Name,Department
101,John,IT
102,Sara,HR
103,David,Finance
After reading the file, the data may contain a repeating Row element.
You can configure:
Repeating Element = Row
Current Element Name = InputRow
The integration then processes:
Row 1 → InputRow
Row 2 → InputRow
Row 3 → InputRow
Oracle’s FTP adapter documentation specifically demonstrates using a second For Each action to iterate over individual rows after a file has been staged and read.
Nested For Each Loops in OIC
Sometimes data contains multiple levels of repeating elements.
For example:
Orders
|
+--- Order 1
| |
| +--- Line 1
| +--- Line 2
|
+--- Order 2
|
+--- Line 1
+--- Line 2
Here, both Orders and Lines are repeating elements.
You can use nested For Each actions.
For Each Order
|
+--- Process Order
|
+--- For Each Order Line
|
+--- Process Line
Oracle recommends first creating a For Each for the parent repeating element and then creating another For Each within its scope for the child repeating element.
For Each vs While Loop in OIC
For Each and While are both looping mechanisms, but they solve different problems.
| Feature | For Each | While |
|---|---|---|
| Main purpose | Process collection items | Repeat while condition is true |
| Input | Repeating element | Condition |
| Number of iterations | Based on collection | Based on condition |
| Common use | Employees, orders, files | Conditional processing |
| Collection required | Yes | No |
| Nested loops | Supported | Supported |
For example:
For Each
For every employee
Process employee
While
While status != COMPLETE
Check status
Oracle documents While as a separate action used to loop over actions or invokes while a specified condition remains satisfied.
Sequential vs Parallel Processing
In scheduled integrations, OIC can provide a Process items in parallel option for a For Each action.
When enabled, iterations can be processed in parallel rather than sequentially.
Sequential Processing
Employee 1
↓
Employee 2
↓
Employee 3
↓
Employee 4
The next iteration waits for the previous processing.
Parallel Processing
Employee 1 ──→
Employee 2 ──→
Employee 3 ──→
Employee 4 ──→
Multiple iterations can execute concurrently.
When should you use parallel processing?
Parallel processing can be useful when:
- Records are independent.
- Processing time is significant.
- Order of processing is not important.
- The target application can handle concurrent requests.
Be careful when multiple iterations update the same shared resource or depend on a specific sequence.
Error Handling in For Each
Error handling is important when processing multiple records.
Suppose there are 100 employees and employee number 45 fails.
You may need to determine:
- Should the complete integration fail?
- Should the failed employee be logged?
- Should processing continue?
- Should the failed record be retried?
You can use Scope and fault-handling mechanisms inside the For Each flow to organize error handling.
For example:
For Each Employee
|
+--- Scope
|
+--- REST Invoke
|
+--- Assign
|
+--- Fault Handler
|
+--- Logger
This approach can help isolate processing logic and make troubleshooting easier.
Retry Option in Scheduled Integrations
For scheduled integrations, OIC provides an Enable Retry option for the For Each action.
Oracle documentation states that when enabled, a For Each branch error can be automatically retried, with up to three retries supported.
This can be useful when temporary failures occur.
For example:
Iteration
↓
REST API Call
↓
Temporary Failure
↓
Retry
↓
Success
However, retries should be used carefully when the target operation is not idempotent, because repeating an operation could potentially create duplicate effects.
Important Restrictions of For Each in OIC
There are several important rules to remember.
1. The selected element must be repetitive
You cannot simply select any scalar field as the repeating element.
The element must represent a collection/repeating structure.
2. Parent restrictions apply
Oracle specifies that the parent of the selected repeating element must not itself be repetitive in the same selection context.
3. Nested repeating structures require nested loops
If you have:
Order[]
|
+--- Line[]
create the parent loop first and then the child loop inside it.
4. Be careful with Stop
A Stop action inside a For Each has special behavior. Oracle notes that when Stop is configured inside a For Each, the entire integration terminates when the For Each is processed for the first time.
Therefore, don’t assume Stop behaves like a simple “break” statement that exits only the current iteration.
Global Variables and For Each
Using global variables inside For Each loops requires caution.
Oracle recommends limiting global variables in For Each loops because global variable handling can require database access and introduce additional performance overhead. Local variables are preferable for logic that is specific to the loop’s local scope.
A good approach is:
For Each
|
+--- Local processing
+--- Local variables
instead of unnecessarily updating global variables during every iteration.
Common Mistakes While Using For Each
Mistake 1: Selecting the Wrong Element
If you select a non-repeating field instead of a collection, the For Each configuration will not work as expected.
Solution: Identify the repeating element in the source structure before configuring the loop.
Mistake 2: Confusing Current Element with Repeating Element
For example:
Repeating Element = employees
Current Element = employee
These are not the same concept.
The first identifies the collection.
The second identifies the current item being processed.
Mistake 3: Putting Actions Outside the Loop
If an action needs to execute for every record, it must be placed inside the For Each scope.
Incorrect:
For Each Employee
|
+--- Assign
REST Invoke
Correct:
For Each Employee
|
+--- Assign
|
+--- REST Invoke
Mistake 4: Using Parallel Processing Without Considering Dependencies
Parallel processing can improve throughput, but it may cause issues if records must be processed in a specific order.
For example:
Create Customer
↓
Update Customer
should not necessarily be processed concurrently for the same customer.
Mistake 5: Excessive Global Variable Usage
Updating shared global variables from many iterations can introduce unnecessary complexity and performance overhead.
Use local variables whenever possible.
Best Practices for For Each in OIC
1. Identify the Collection Clearly
Before creating the loop, determine exactly which element contains multiple records.
2. Use Meaningful Names
Instead of:
current1
use:
currentEmployee
or:
currentOrder
Meaningful aliases make integrations easier to understand.
3. Keep Loop Logic Focused
Avoid putting unnecessary actions inside a For Each.
A smaller loop is easier to troubleshoot and maintain.
4. Use Parallel Processing Carefully
Use parallel processing when records are independent and the target system supports concurrent requests.
5. Design Error Handling
Decide how the integration should behave when one iteration fails.
6. Avoid Unnecessary Global Variables
Prefer local variables for iteration-specific processing.
7. Test With Different Collection Sizes
Test your integration with:
1 record
10 records
100 records
Large dataset
Empty dataset
Invalid record
This helps identify performance and error-handling issues before production deployment.
Real-World Use Cases of For Each in OIC
For Each is commonly useful in scenarios such as:
Oracle HCM Integration
Get Employees
↓
For Each Employee
↓
Update Target System
Oracle ERP Integration
Get Invoices
↓
For Each Invoice
↓
Validate
↓
Send to External System
File Processing
List Files
↓
For Each File
↓
Download
↓
Read
↓
Process
Order Processing
Get Orders
↓
For Each Order
↓
Process Order
↓
Process Order Lines
Customer Synchronization
Get Customers
↓
For Each Customer
↓
Transform
↓
Invoke CRM API
For Each Loop — Interview Questions
If you are preparing for an OIC interview, these are important questions to practice:
1. What is For Each in OIC?
For Each is an OIC action used to iterate over a repeating element and execute one or more actions for every occurrence.
2. What is a Repeating Element?
A repeating element represents a collection of multiple instances, such as employees, orders, files, or invoice lines.
3. What is Current Element Name?
It is an alias used to reference the individual element being processed during the current iteration.
4. Can For Each loops be nested?
Yes. Nested For Each loops can be used when working with hierarchical repeating structures such as orders and order lines.
5. Can For Each process items in parallel?
Yes, for scheduled integrations, OIC provides a Process items in parallel option.
6. What is the difference between For Each and While?
For Each processes each item in a collection, while While repeats actions as long as a condition is satisfied.
7. How do you handle errors inside a For Each?
You can use scopes and fault-handling mechanisms to organize error processing within the loop.
Final Thoughts
The For Each action is one of the most important looping constructs in Oracle Integration Cloud. Whenever an integration needs to process multiple records, files, orders, employees, or other repeating data, For Each can help you build reusable and scalable processing logic.
The key concepts to remember are:
Repeating Element
↓
Current Element
↓
For Each
↓
Actions for Each Item
↓
Error Handling
For real-world OIC development, don’t just focus on creating the loop. Also consider error handling, parallel processing, performance, variable scope, retries, and dependencies between records.
Once you understand these concepts, you can confidently design integrations for bulk data processing and complex hierarchical payloads.
Learnomate Technologies helps professionals build practical skills in Oracle technologies, cloud platforms, databases, and integration technologies. If you’re learning Oracle Integration Cloud, mastering actions such as For Each, While, Switch, Scope, Assign, Stage File, and Invoke is an important step toward becoming a skilled OIC developer.
Frequently Asked Questions
What is For Each in OIC?
For Each is an OIC action that loops over a repeating element and executes the actions inside the loop for each item.
What is a repeating element in OIC?
A repeating element is a collection containing multiple instances of the same type of data, such as employees, orders, files, or invoice lines.
Can I use nested For Each loops in OIC?
Yes. Nested For Each loops are useful for hierarchical data such as orders containing multiple order lines.
Can For Each run records in parallel?
Yes. In scheduled integrations, OIC provides an option to process items in parallel.
What is the difference between For Each and While in OIC?
For Each iterates over a collection, whereas While repeatedly executes actions while a specified condition remains true.
Can I process files using For Each?
Yes. OIC provides For Each functionality for iterating over files returned from file operations and for processing individual records within staged files.





