ForEach state allows you to define a set of actions to execute for each element in an array or list defined in State Data. For example,
for Each device in device array, check the devices is in sync. Whilst the serverless workflow specification defines support
for Parallel and Sequential execution of actions, current implementation only supports sequential execution of actions for
each element in array.
Parameter
|
Description
|
inputCollection |
Workflow expression in jq that points to an array in State Data. |
iterationParam |
Name of the parameter that can be referenced in action for each data element. |
outputCollection |
Workflow expression in jq that points to an array in State Data that the result will be appended to. If array doesn't exist,
it will be created.
|
{
"id": "example",
"version": "1.0",
"specVersion": "0.9",
"start": "InjectData",
"functions": [
{
"name": "HelloWorld",
"operation": "HelloWorld"
}
],
"states": [
{
"name": "InjectData",
"type": "inject",
"data": {
"people": [
{
"Firstname": "Peter",
"Surname": "Parker"
},
{
"Firstname": "Thor",
"Surname": "Odinson"
},
{
"Firstname": "Bruce",
"Surname": "Banner"
}
]
},
"transition":{
"nextStat": "SayHelloToEveryone"
}
},
{
"name": "SayHelloToEveryone",
"type": "foreach",
"inputCollection": "${ .people }",
"iterationParam": "person",
"outputCollection": "${ .messages }",
"actions": [
{
"name": "SayHello",
"functionRef":{
"refName": "HelloWorld",
"arguments": {
"name": "${ .person.Firstname + \" \" + .person.Surname }"
}
}
}
],
"end": {
"terminate": "true"
}
}
]
}