For Each Element
Summary
- Internal name:
ForEachElement - Category: Collections
- Purpose: Run a nested sub-workflow once per element of a list variable, exposing the current element in a loop variable.
- Task type: Connector — see Tasks Overview § Connector Tasks for what this means before reading further.
Compatibility
-
Minimum AndroMate version:
1.1.0 -
Maximum AndroMate version:
1.1.0 -
Minimum Android:
Android 13 (API 33) -
Maximum Android tested:
Android 16 (API 36) -
Supported manufacturers:
- ✅ All manufacturers
-
Required permissions:
- None (permissions depend entirely on whatever tasks are placed inside
"do")
- None (permissions depend entirely on whatever tasks are placed inside
Detailed description
The For Each Element task iterates a list variable and runs the sub-workflow embedded under its "do" key once per element, writing the current element into element_variable_input before each pass — the list-iteration counterpart to Iterate's numeric range loop.
In the outer graph, ForEachElement behaves exactly like a normal task — one incoming link, one outgoing "to" link, followed once every element has been processed. All the repetition happens inside the task, not in the graph's Links.
The sub-workflow under "do" shares the same variable dictionary as the rest of the workflow: it can read any variable declared in the outer Start, and any output it produces is visible to tasks that come after ForEachElement in the outer graph too.
Input parameters
| Parameter | Type | Required | Possible values | Android Compatibility | AndroMate Compatibility | Default |
|---|---|---|---|---|---|---|
list_variable_input |
String | Yes | A declared list variable name starting with $ |
Android 13 (API 33) → Android 16 (API 36) | 1.1.0 → 1.1.0 | [] |
element_variable_input |
String | Yes | A declared variable name starting with $ |
Android 13 (API 33) → Android 16 (API 36) | 1.1.0 → 1.1.0 | "" |
do |
Object (sub-workflow) | Yes | A nested workflow object — see Iterate's The do sub-workflow for the shape (identical here) |
Android 13 (API 33) → Android 16 (API 36) | 1.1.0 → 1.1.0 | — |
Output parameters
The For Each Element task itself produces no outputs. Any variable written by a task inside "do" updates the shared workflow context normally, as if that task ran directly in the outer graph.
Exceptions
| Code | Exception Name | Description |
|---|---|---|
COLLECTION-TASK-002 |
List Variable Name Invalid | element_variable_input is empty, or isn't a valid $variable reference. |
CONNECTOR-TASK-ERROR-001 |
No Sub Tasks | The "do" field is missing or empty — a connector task must contain a sub-workflow to run. |
Note: an empty list_variable_input is not an error — the loop simply runs zero times.
Execution flowchart
flowchart TD
Start([▶ ForEachElement]) --> CheckVar{element_variable_input\nvalid $variable?}
CheckVar -->|No| E1[❌ COLLECTION-TASK-002\nLIST_VARIABLE_NAME_INVALID]
CheckVar -->|Yes| CheckDo{do sub-workflow\npresent?}
CheckDo -->|No| E2[❌ CONNECTOR-TASK-ERROR-001\nNO_SUB_TASKS]
CheckDo -->|Yes| Loop[i = 0]
Loop --> CheckSize{i < list.size?}
CheckSize -->|No| Continue[➡️ Follow outer 'to' link]
CheckSize -->|Yes| SetVar[💾 Set element_variable_input = list#91;i#93;]
SetVar --> RunSub[▶ Run do sub-workflow]
RunSub --> Increment[i = i + 1]
Increment --> CheckSize
Continue --> Success([✅ VoidResult])
E1 --> Error([❌ Exception])
E2 --> Error
style Start fill:#e3f2fd
style Success fill:#c8e6c9
style Error fill:#ffcdd2
style RunSub fill:#fff9c4
style SetVar fill:#c8e6c9
How it works:
- Validate
element_variable_input: raisesCOLLECTION-TASK-002if it's empty or not a$variablereference. - Check
do: raisesCONNECTOR-TASK-ERROR-001if the sub-workflow is missing or empty. - Loop: for each element in
list_variable_input, in order: - writes the element into
element_variable_input, - runs the
"do"sub-workflow to completion (from itsStartSubTaskto itsEnd). - Continue: once every element has been processed (or immediately, if the list is empty), the engine follows the outer
"to"link.
Input parameter details
1. Input parameter: list_variable_input
The name of a declared list variable to iterate.
Example
Details
- Must start with
$and must already be declared in the outerStart.variables(typically built withInitList/ListAdd).
2. Input parameter: element_variable_input
The name of a declared variable that receives the current element (as a string) before each pass.
Example
Details
- Must start with
$and must already be declared in the outerStart.variables. - Read as a literal variable name — no resolution applied to this field itself.
Complete JSON example
Builds a 3-item list and sends one SMS per item:
{
"Start": [
{
"id": "0",
"variables": [
{ "variableName": "$my_list", "variableValue": "[]", "is_kpi": false },
{ "variableName": "$item", "variableValue": "", "is_kpi": false }
]
}
],
"InitList": [
{ "id": "1", "list_variable_input": "$my_list" }
],
"ListAdd": [
{ "id": "2", "list_variable_input": "$my_list", "value_input": "111" },
{ "id": "3", "list_variable_input": "$my_list", "value_input": "222" },
{ "id": "4", "list_variable_input": "$my_list", "value_input": "333" }
],
"ForEachElement": [
{
"id": "5",
"title": "Notify every recipient",
"list_variable_input": "$my_list",
"element_variable_input": "$item",
"do": {
"StartSubTask": [{ "id": "sub-0" }],
"SendSMS": [
{ "id": "sub-1", "msisdn": "$item", "message_body": "Hello!" }
],
"End": [{ "id": "sub-100" }],
"Links": [
{ "from": "sub-0", "to": "sub-1" },
{ "from": "sub-1", "to": "sub-100" }
]
}
}
],
"End": [{ "id": "100" }],
"Links": [
{ "from": "0", "to": "1" },
{ "from": "1", "to": "2" },
{ "from": "2", "to": "3" },
{ "from": "3", "to": "4" },
{ "from": "4", "to": "5" },
{ "from": "5", "to": "100" }
]
}