For Each is a loop control component, which is similar to for/foreach in several programming languages. In For Each, you can configure a subflow to execute the subflow logic for each element in the specified data set.
Parameter | Data Type | Description | Required | Default Value |
---|---|---|---|---|
Data set | string, list, dict, and int | The data set to be traversed.
|
Yes | None |
Counter | string | The counter is a variable, which stores the current number of iterations and starts from 0 .You need to enter a variable name such as msg.vars.get('#counter variable#') to use the counter.For example, if the counter variable is set to the default value counter :In the first loop, msg.vars.get('counter') will be 0 .In the second loop, msg.vars.get('counter') will be 1 . |
Yes | counter |
Root message | string | The root message is also a variable, which stores the message of the main flow. You need to enter a variable name. You can enter msg.vars.get('#root message name#').payload to access the payload data of the main flow.If the default value rootMessage is used, you can use msg.vars.get('rootMessage').payload to access the payload data of the main flow in the For Each subflow. |
Yes | rootMessage |
Note:Generally, you only need to configure the data set.
Preview Field | Data Type | Description |
---|---|---|
payload | any | Input value in each traversal, which is also an element in the data set. |
index | int | Position in each traversal. This field represents the subscript position of the current input value in the data set, which starts from 0 . |
The data preview content is visible only in the subflow. Components in the subflow can directly use payload
and index
in the For Each component.
message
input to the subflowmessage Attribute |
Value |
---|---|
payload | An element in the data set. For example, if the data set to be iterated is [1,2,3] :In the first loop, payload in the subflow will be 1 .In the second loop, payload will be 2 .If the data set to be iterated is {"key":"key1", "value":"value1"} of dict type:In the first loop, payload in the subflow will be value1 .In the second loop, payload will be value2 . |
error | Null. |
attribute | Null. |
variable | This attribute inherits the variable of the main flow and has two new variables: counter and root message. If you use the default values of the two new variables, you can use expressions msg.vars.get('counter') and msg.vars.get('rootMessage') to access them.If Set Variable is used in For Each, the new variables will be added to variable during subflow execution. |
The For Each component doesn't change the content of message
, and subsequent nodes only notice the changes in variables.
The following describes how to use the For Each component to traverse the list and add numbers and prefixes to elements in the list.
listResult
.listResult
variable.
Was this page helpful?