> For the complete documentation index, see [llms.txt](https://docs.onum.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onum.com/pipelines/actions/advanced/for-each.md).

# For Each

{% hint style="info" %}
See the changelog of this Action type [here](/actions-changelog/for-each.md).
{% endhint %}

## Overview

The **For Each** action divides a list field with different entries into different output events, along with the position they occupy in the list (being the first position `0`).

For example, an input list containing `[a,b,c]` will generate three outputs, with these fields added to the event:

* `elementValueOutField: a`; `elementIndexOutField: 0`
* `elementValueOutField: b`; `elementIndexOutField: 1`
* `elementValueOutField: c`; `elementIndexOutField: 2`

{% hint style="warning" %}
In order to configure this action, you must first link it to a Listener. Go to [Building a Pipeline ](/pipelines/building-a-pipeline.md)to learn how this works.
{% endhint %}

## Ports

These are the input and output ports of this Action:

<details>

<summary>Input ports</summary>

* **Default port** - All the events to be processed by this Action enter through this port.

</details>

<details>

<summary>Output ports</summary>

* **Default port** - Events are sent through this port if no error occurs while processing them.
* **Error port** - Events are sent through this port if an error occurs while processing them.

</details>

## Configuration

{% stepper %}
{% step %}
Find **For Each** in the **Actions** tab (under the **Advanced** group) and drag it onto the canvas.
{% endstep %}

{% step %}
To open the configuration, click the Action in the canvas and select **Configuration**.
{% endstep %}

{% step %}
Enter the required parameters:

<table><thead><tr><th width="234">Parameter</th><th>Description</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>Input</strong></td><td>Choose the field that contains the list you want to divide.</td><td></td></tr><tr><td><strong>Output field</strong></td><td>Name of the new field where each iterated element will be stored. This will be the same type as the input field list.</td><td></td></tr><tr><td><strong>Index field</strong></td><td>Name of the new field that will show the position of each element in the list.</td><td></td></tr></tbody></table>
{% endstep %}

{% step %}
Click **Save** to complete the process.
{% endstep %}
{% endstepper %}

## Example

Imagine you receive a list-type field containing a string of five IPs:

`127.0.0.1`,`127.0.0.2`,`127.0.0.3`,`127.0.0.4`,`192.168.0.1`

{% stepper %}
{% step %}
Add the **For Each** Action to your Pipeline and link it to your required Data sink.
{% endstep %}

{% step %}
Now, double-click the **For Each** Action to configure it. You need to set the following config:

<table><thead><tr><th width="227">Operation</th><th>Parameters</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>Input</strong></td><td>In this case, we choose the field <code>ipsList</code> that contains our IP list.</td><td></td></tr><tr><td><strong>Output field</strong></td><td>We're naming the new field <code>ipValue</code>.</td><td></td></tr><tr><td><strong>Index field</strong></td><td>We're naming the new field <code>ipIndex</code>.</td><td></td></tr></tbody></table>
{% endstep %}

{% step %}
Click **Save** to apply the configuration.
{% endstep %}

{% step %}
Now link the *Default* output port of the Action to the input port of your Data sink.
{% endstep %}

{% step %}
Finally, click **Publish** and choose in which clusters you want to publish the Pipeline.
{% endstep %}

{% step %}
Click **Test pipeline** at the top of the area and choose a specific number of events to test if your data is transformed properly. Click **Debug** to proceed.
{% endstep %}
{% endstepper %}

The Action will create a separate event for each element of the string, each event containing two fields (value and index).
