Skip to main content

For Each Task

The foreach task is used to iterate over a collection of items and execute a set of tasks for each item in the collection.

ForEach Task structure

Example of For Each task step.:

activities:
- name: "UpdateCommodityStatus"
description: "Update the status of a commodity for shipped orders."
steps:
- task: "foreach"
collection: "order.commodities"
item: "item"
conditions: "[item.status] != 'Shipped'"
steps:
- task: "UpdateCommodityStatus"
inputs:
commodityId: "{{item.id}}"
status: "Shipped"

The ForEach activity is a YAML object. The ForEach activity has the following keys:

  • condition (optional) - The Condition key is a string. The Condition key is used to define the condition of the activity. The Condition key is optional. If the Condition key is not defined then the activity is executed unconditionally.
  • collection (optional) - The Collection key is a string. The Collection key is used to define the collection to iterate over. The Collection key is required. The collection can be a list of items or a GraphQL response path object.
  • item (optional) - The Item key is a string. The Item key is used to define the name of the variable that will hold the current item in the collection. The Item key is required.
  • variables (optional) - The Variables key is a string. The Variables key is used to define the variables to use in the query. The Variables key is required.
  • steps (required) - The Steps key is a list of actions that should be taken during this activity. Must have at least one action.
  • continueOnError (optional) - The ContinueOnError key is a boolean. The ContinueOnError key is used to define if the workflow should continue if an error occurs during mapping. The ContinueOnError key is optional. If the ContinueOnError key is not defined then the workflow will stop if an error occurs during mapping.