The Iterate Task allows you to loop through a list of items and perform tasks for each item. This task is useful for iterating over arrays, maps, or sets and executing tasks for each element.
This is similar to the for-each loop in programming languages, where you can execute a block of code for each item in a collection.
To use the Iterate Task, you need to define it in your workflow file and specify the items to iterate over.
You can't define a
tasksfield in the Iterate Task. Instead, you should define the tasks in theloopOverfield.
Here is an example of an Iterate Task in a workflow file:
{
"name": "sample-workflow",
"tasks": [
{
"name": "loop_items",
"handler": "iterate",
"parameters": {
"items": [1, 2, 3, 4, 5]
},
"loopOver": [
{
"name": "log_item",
"handler": "log",
"parameters": {
"message": "Item ${task.output.item}"
}
}
]
}
]
}items: An array, map, or set of items to iterate over. This is required.
loopOver: An array of tasks to execute for each item.
The task's name will be calculated based on the iteration index, see the For Task documentation for more details.
The Iterate Task will loop through the specified items and execute the tasks in the loopOver array for each item.
The output of the Iterate task will contain:
iteration: The current iteration count starting from0.item: The current item being processed.
There is a special task field loopOver which is an array of tasks that were executed for each iteration.
The Iterate Task allows you to iterate over a list of items and perform tasks for each item.
Define the items using the items parameter, and specify the tasks to execute in the loopOver array.