# For Each

{% hint style="info" %}
See the changelog of this Action type [here](/actions/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`

<figure><picture><source srcset="/files/iUiInZP8vLvU3LyKbx3m" media="(prefers-color-scheme: dark)"><img src="/files/MswtclQhN9JABjRIFhao" alt=""></picture><figcaption></figcaption></figure>

{% hint style="warning" %}
In order to configure this action, you must first link it to a Listener. Go to [Building a Pipeline ](/the-workspace/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><mark style="color:red;"><strong>*</strong></mark></td><td>Choose the field that contains the list you want to divide.</td><td></td></tr><tr><td><strong>Output field</strong><mark style="color:red;"><strong>*</strong></mark></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><mark style="color:red;"><strong>*</strong></mark></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).

<figure><img src="/files/wGkhXhCzWAumeugCT08r" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onum.com/the-workspace/pipelines/actions/advanced/for-each.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
