Introduction
In modern cloud integrations, handling repeating data structures efficiently is critical. One of the most powerful constructs available in Oracle Integration Cloud is the For Each action, which allows consultants to iterate through collections such as arrays, repeating XML nodes, or JSON lists.
If you are working on real-time integrations between SaaS applications like HCM, ERP, or external systems hosted on Oracle Cloud Infrastructure, mastering the For Each in Oracle Integration Cloud is not optional—it is essential.
From my implementation experience, most integration failures in early projects come from improper handling of repeating data. This blog will walk you through how to correctly design, configure, and troubleshoot For Each loops in OIC Gen 3.
What is For Each in Oracle Integration Cloud?
The For Each action in OIC is a looping construct used to iterate over repeating elements in a payload.
In simple terms:
- If your input has multiple records (employees, invoices, orders)
- And you need to process each record individually
→ You use For Each
Example
If your payload contains:
- 100 employee records from HCM
- You need to call an API for each employee
Instead of writing 100 integrations, you use For Each to loop through the list dynamically.
Key Features of For Each Action
1. Iteration Over Collections
Supports:
- JSON arrays
- XML repeating nodes
- CSV converted structures
2. Scoped Variable Handling
Each iteration has its own context, avoiding data conflicts.
3. Nested Loop Capability
You can use For Each inside another For Each, useful in:
- Header → Line → Distribution scenarios
4. Parallel Processing Option
In OIC Gen 3:
- You can enable parallel execution for performance optimization
5. Fault Isolation
Errors can be handled per iteration using:
- Scope
- Fault handlers
Real-World Integration Use Cases
Use Case 1 – Employee Data Sync from HCM
Scenario:
- Extract multiple employee records from Oracle HCM
- Send each employee to a third-party payroll system
Solution:
- Use For Each to iterate through employee list
- Call REST API for each record
Use Case 2 – Bulk Invoice Processing
Scenario:
- ERP sends multiple invoices
- Each invoice needs validation and submission
Solution:
- Use For Each loop
- Perform validation per invoice
- Route success/failure
Use Case 3 – Order Integration with Line Items
Scenario:
- Order contains multiple line items
- Each line must be processed separately
Solution:
- Outer For Each → Orders
- Inner For Each → Line Items
Architecture / Technical Flow
Typical flow using For Each:
- Receive Payload (JSON/XML)
- Parse Structure
- Identify Repeating Node
- Loop Using For Each
- Perform Actions Inside Loop:
- Mapping
- API Call
- Transformation
- Exit Loop
- Send Final Response
Visual Flow (Conceptual)
Prerequisites
Before implementing For Each:
1. Integration Created
- App Driven or Scheduled Integration
2. Proper Payload Structure
- JSON or XML with repeating elements
3. Connections Configured
- REST Adapter
- SOAP Adapter
- FTP Adapter (if needed)
4. Understanding of XPath/JSON Path
- Required to select repeating node
Step-by-Step Build Process
Let’s walk through a practical example.
Scenario:
Process multiple employees from a JSON payload.
Step 1 – Create Integration
Navigate to:
Home → Integrations → Create
- Choose: App Driven Orchestration
- Name:
Process_Employees_ForEach
Step 2 – Define Trigger
Use REST Adapter:
Sample payload:
Step 3 – Add For Each Action
Drag For Each from Actions panel.
Configure:
-
Repeating Element:
/employees -
Loop Name:
EmployeeLoop - Execution Mode:
- Sequential (default)
- Parallel (optional)
Step 4 – Add Mapping Inside Loop
Inside For Each:
- Drag Assign or Map
Example:
- Map employee name
- Map salary
Step 5 – Add Invoke (Optional)
Call external API:
- REST Adapter
- Pass current employee details
Step 6 – Add Logger
Best practice:
- Add logger inside loop
- Helps debug each iteration
Step 7 – Save and Activate
Click:
- Save
- Activate
Testing the Technical Component
Test Payload
Expected Behavior
- Loop runs twice
- Each employee processed individually
Validation Checks
- Check Activity Stream
- Verify:
- Each iteration executed
- API invoked twice
- No data overwrite
Common Errors and Troubleshooting
1. Incorrect XPath
Issue: Loop not executing
Cause: Wrong repeating element
Fix: Validate path using mapper
2. Empty Payload
Issue: For Each skipped
Fix: Add condition before loop:
- If size > 0
3. Variable Scope Issues
Issue: Data overwritten
Fix: Use local variables inside loop
4. Performance Issues
Issue: Slow processing
Fix: Enable parallel processing (carefully)
5. API Rate Limits
Issue: External API fails
Fix:
- Add throttling logic
- Use wait action
Best Practices
1. Always Validate Input Size
Avoid running loops on empty data.
2. Use Parallel Processing Carefully
Only when:
- No dependency between iterations
3. Use Scope with Fault Handling
Wrap loop logic inside Scope:
- Catch per iteration errors
4. Logging is Mandatory
Log:
- Input data
- Iteration index
- API response
5. Avoid Deep Nesting
Too many nested loops:
- Hard to debug
- Impacts performance
6. Use Bulk APIs When Available
Instead of looping:
- Prefer bulk operations
Real Consultant Insight
In one implementation:
- Client was sending 5000 employee records
- Using sequential For Each → took 40 minutes
Solution:
- Enabled parallel processing
- Batch split (500 records per loop)
Result:
- Processing time reduced to 6 minutes
Summary
The For Each in Oracle Integration Cloud is one of the most frequently used and powerful constructs for handling repeating data. Whether you are integrating HCM, ERP, or external systems, understanding how to correctly implement loops will significantly improve your integration efficiency.
Key takeaways:
- Always identify repeating elements correctly
- Use sequential vs parallel wisely
- Handle errors per iteration
- Optimize performance for large datasets
FAQs
1. Can we use nested For Each loops in OIC?
Yes. Nested loops are supported and commonly used in:
- Orders → Lines → Distributions scenarios
However, avoid excessive nesting for performance reasons.
2. What is the difference between sequential and parallel For Each?
- Sequential: Processes one record at a time
- Parallel: Processes multiple records simultaneously
Use parallel only when there are no dependencies.
3. How do I debug For Each issues?
- Use Activity Stream
- Add logger inside loop
- Check XPath expressions carefully
Additional Reference
For more detailed product documentation, refer to:
https://docs.oracle.com/en/cloud/saas/index.html