Skip to main content

forEach

A for each expression.

The element for an array looks like this:

{
"element": {}, // the element
"index": 0, // the index of the element. 0 based
"count": 5, // the list size
}

The element for an object like this:

{
"element": {}, // the element
"key": "theKey", // the key of the element.
}

Field Configurations

KeyTypeDescriptionDefault Value
"params" (required)Objectundefinednull

Parameters

KeyTypeDescriptionDefault Value
"actions" (required)ArrayList of actions to be execute on each element.null
"async"BooleanSpecifies whether the action should perform asynchronously.null
"leadingDelimiter"StringLeading delimiter for templates inside the action list.null
"path" (required)StringThe path to the array or object which should be iterated.null
"trailingDelimiter"StringLeading delimiter for templates inside the action list.null

Inherited

From Base Action

Base Action

Field Configurations

KeyTypeDescriptionDefault Value
"dynamicParams"ObjectDynamic params to retrieve data from a specific context e.g. a userSetting.null
"leadingDelimiter"StringThe leading mustache delimiter to use.null
"params"Object,ArrayObject containing the properties of the action.null
"trailingDelimiter"StringThe trailing mustache delimiter to use.null
"type"StringType name of the action.null

Examples

Example 1: Iterate over an array

Goal: Show a message for each element in the array.

{
"type": "forEach",
"params": {
"path": "theList",
"leadingDelimiter": "{:",
"trailingDelimiter": ":}",
"actions": [
{
"type": "if",
"params": {
"condition": {
"mode": "equal",
"left": "{:index:}",
"right": "0"
},
"then": [
{
"type": "showMessage",
"params": {
"text": "first: {:element.text:} of {:count:}"
}
}
],
"else": [
{
"type": "showMessage",
"params": {
"text": "second: {:element.text:} of {:count:}",
"asToast": true
}
}
]
}
}
]
}
}

Example 2: Iterate over an object

Goal: Show a message for each element in the object.

{
"type": "forEach",
"params": {
"path": "theObject",
"leadingDelimiter": "{:",
"trailingDelimiter": ":}",
"actions": [
{
"type": "if",
"params": {
"condition": {
"mode": "equal",
"left": "{:key:}",
"right": "first"
},
"then": [
{
"type": "showMessage",
"params": {
"text": "first: {:element.text:} of {:key:}"
}
}
],
"else": [
{
"type": "showMessage",
"params": {
"text": "second: {:element.text:} of {:key:}",
"asToast": true
}
}
]
}
}
]
}
}