For Each Loop task

TheFor Each Loop task lets you make repeated calls to a sub-integration from your current (main) integration. The task iterates over the configured array variable and calls the sub-integration for each element in the array. The number of times the sub-integration is called is equal to the size of the array variable.

TheAPI Trigger ID and theIntegration name identifies the sub-integration you want to run.

The task also lets you collect the response from each sub-integration run and store the value in your current integration for use in downstream tasks. You can use any of the following approach to collect the responses:

  • Collate the response of each run in an array variable, where each element of the array has the response from one particular run. To collate the responses, configure theCollect values from sub-integration output(s) property.
  • Aggregate the responses of all the runs in a single variable. To aggregate the responses, configure theResponse parameter override mapping property.
Note:

Before you begin

Configuration properties

The following table describes the configuration properties of theFor Each Loop task.

PropertyData typeDescription
API Trigger IDStringTrigger ID of the sub-integration to run.

This value is available in theTrigger ID field of theAPI Trigger in the sub-integration.

Integration nameStringName of the sub-integration to run.
List to iterateAn array of type Boolean, String, Integer, Double, or JSON.List of values for which the sub-integration should run. The sub-integration runs for each value in the list, one after the other.

You can pass the iterated value to the sub-integration by setting theIteration element sub-integration mapping property. In this property, specify the variable in the sub-integration to which the iterated value must be mapped.

Iteration element sub-integration mappingN/AVariable in the sub-integration for which the current iterated element must be assigned.
Map to additional sub-integration input(s)N/AAdditional values to pass from the current integration to the sub-integration.

The values of this property are in the form of key-value pairs, where the key is a variable in the current integration, and the value is the corresponding input variable in the sub-integration. For example, suppose your main integration has theproductID variable, which you want to map to thesubIntProductID sub-integration variable; you would selectproductID from theIntegration variable to map from drop-down and selectsubIntProductID in theSubintegration input to map to drop-down.

Collect values from sub-integration output(s)N/ACollate the results of the sub-integration runs.

Every time the sub-integration runs, you can store the output of the sub-integration in an array variable of the current integration. Select the sub-integration's output variable from theSub-integration output to collect from drop-down and the array variable in current integration from theIntegration variable to collect into drop-down. Each element of the array has the response from a particular sub-integration run. For example, if the array variable isresultsArray,resultsArray[0] has the response from the first run andresultsArray[1] has the response from the second run.

Response parameter override mappingN/ARead the output variable of a sub-integration run and store it in a variable of the current integration.

Select the sub-integration's output variable from theSub-integration output to map from drop-down, and select the corresponding variable in the current integration from theIntegration variable to override drop-down. You can send the overridden variable in the current integration to the next sub-integration run by mapping the variable in theMap to additional sub-integration input(s) property. As a result, you can cumulatively aggregate the responses from the sub-integration runs.

Loop metadataJSON arrayThe output variable that has the execution details of the sub-integrations like sub-integration execution ID, errors messages, and variable values passed during execution. Loop metadata contains variables including the following output variables:current_iteration_count,sub_integration_execution_ids,failure_location,current_element,iteration_element, andfailure_message.Warning: In the Loop metadata, you will find duplicate keys for the output variable–for example,Current Iteration Count andcurrent_iteration_count. We recommend you to use the variables that contain the underscore (_) symbol because the other keys are being deprecated.

Examples

The following sections provide detailed examples of how to configure and use theFor Each Loop task for specific scenarios. These examples illustrate the configuration steps for different use cases:

Iterate and pass each element

Assume you have a main integration with an array variable namedproductIds containing values like["P1", "P2", "P3"]. To call a sub-integration namedGetProductDetails for each product ID, configure theFor Each Loop task as follows:

  • SetList to iterate toproductIds.
  • SetIteration element sub-integration mapping to map the current element ofproductIds to a variable inGetProductDetails, for example,subIntProductId.

Each execution ofGetProductDetails then receives one product ID fromproductIds.

Collect sub-integration outputs

As in the previous example, assumeGetProductDetails returns a JSON object in an output variable calledproductInfo.

To collect allproductInfo outputs from each sub-integration execution and store them as elements in an array variable within the main integration:

  • ConfigureCollect values from sub-integration output(s).
  • SelectproductInfo fromSub-integration output to collect from.
  • Select an array variable in the main integration, for example,allProductDetails, fromIntegration variable to collect into.

After the loop completes,allProductDetails is an array where each element is theproductInfo JSON from one sub-integration execution.

Aggregate results with response override

Assume you have a main integration that calls a sub-integration (for example,GetProductDetails) for each item in a list, and you want to calculate the total price of all items. To sum up a numeric value returned by each sub-integration execution:

  • Ensure the sub-integration returns a value in an output variableitemPrice.
  • Initialize thetotalPrice variable to0 in the main integration.
  • ConfigureResponse parameter override mapping:
    • MapitemPrice (from sub-integration) tototalPrice (in main integration).
  • In theMap to additional sub-integration input(s) section:
    • MaptotalPrice (from main integration) to an input variable in the sub-integration, for example,currentTotal.
  • In the sub-integration's logic, add the current item's price to thecurrentTotal received from the main integration. Then, return this new sum in the output variable nameditemPrice. This process creates a cumulative aggregation.

Pass additional inputs

If your sub-integrationGetProductDetails needs acurrency code from the main integration, then:

  • In theMap to additional sub-integration input(s) section:
    • Map the main integration variablecurrencyCode to the sub-integration input variablesubIntCurrency.
  • ThiscurrencyCode is passed to every execution of the sub-integration.

Explore the following sample integrations for practical, step-by-step guides and executable examples of the concepts discussed in the preceding sections:

Best practices

For information about the usage limits that apply to theFor Each Loop task, see Usage limits.

Error handling strategy

An error handling strategy for a task specifies the action to take if the task fails due to atemporary error. For information about how to use an error handling strategy, and to know about the different types of error handling strategies, seeError handling strategies.

Quotas and limits

For information about quotas and limits, seeQuotas and limits.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.