> 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/field-generator.md).

# Field Generator

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

## Overview

The **Field Generator** action allows you to add new fields to your events using a given operation. You can select one or more operations to execute, and their resulting values will be set in user-defined event fields.

{% hint style="warning" %}
In order to configure this action, you must first link it to a Listener or another Action. 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 **Field Generator** in the **Actions** tab (under the **Advanced** group) and drag it onto the canvas. Link it to the required [Listener](/listeners.md) and [Data sink](/pipelines/data-sinks.md).
{% endstep %}

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

{% step %}
Choose which operations you want to use to define the new fields in your events:

<table data-search="false"><thead><tr><th width="151">Operation</th><th>Parameters</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>Now</strong></td><td><ul><li><strong>Now</strong> - Select <strong>true</strong> to create a new field with the current Epoch time in the selected time unit.</li><li><strong>Now output field</strong> - Give a name to the new field.</li><li><strong>Now timezone</strong> - Enter the required timezone (for example: <code>UTC</code>, <code>America/New_York</code>, <code>Europe/London</code>...). The default value is <code>UTC</code>.</li><li><p><strong>Output type</strong> - Choose the type of your output dates:</p><ul><li><strong>Unix timestamp</strong> - This is the default value. Choose the required time unit in the <strong>Now time unit</strong> parameter that appears. The available time units are <strong>nanoseconds</strong>, <strong>microseconds</strong>, <strong>milliseconds</strong> &#x26; <strong>seconds</strong>.</li><li><strong>Custom format</strong> - Enter a specific time format for your output dates in the <strong>Custom format</strong> field that appears. For the complete valid format reference, see the <a href="https://github.com/maniartech/gotime/blob/master/docs/core-concepts/nites.md#complete-format-reference">gotime Nites Format Documentation</a>.</li></ul></li></ul></td><td></td></tr><tr><td><strong>Today</strong></td><td><ul><li><strong>Today</strong> - Select <strong>true</strong> to create a new field with the Epoch time corresponding to the current day at <code>00:00:00h</code> in the selected time unit.</li><li><strong>Today output field</strong> - Give a name to the new field.</li><li><strong>Today timezone</strong> - Enter the required timezone (for example: <code>UTC</code>, <code>America/New_York</code>, <code>Europe/London</code>...). The default value is <code>UTC</code>.</li><li><p><strong>Output type</strong> - Choose the type of your output dates:</p><ul><li><strong>Unix timestamp</strong> - This is the default value. Choose the required time unit in the <strong>Today time unit</strong> parameter that appears. The available time units are <strong>nanoseconds</strong>, <strong>microseconds</strong>, <strong>milliseconds</strong> &#x26; <strong>seconds</strong>.</li><li><strong>Custom format</strong> - Enter a specific time format for your output dates in the <strong>Custom format</strong> field that appears. For the complete valid format reference, see the <a href="https://github.com/maniartech/gotime/blob/master/docs/core-concepts/nites.md#complete-format-reference">gotime Nites Format Documentation</a>.</li></ul></li></ul></td><td></td></tr><tr><td><strong>Yesterday</strong></td><td><ul><li><strong>Yesterday</strong> - Select <strong>true</strong> to create a new field with the Epoch time corresponding to the previous day at <code>00:00:00h</code> in the selected time unit.</li><li><strong>Yesterday output field</strong> - Give a name to the new field.</li><li><strong>Yesterday timezone</strong> - Enter the required timezone (for example: <code>UTC</code>, <code>America/New_York</code>, <code>Europe/London</code>...). The default value is <code>UTC</code>.</li><li><p><strong>Output type</strong> - Choose the type of your output dates:</p><ul><li><strong>Unix timestamp</strong> - This is the default value. Choose the required time unit in the <strong>Yesterday time unit</strong> parameter that appears. The available time units are <strong>nanoseconds</strong>, <strong>microseconds</strong>, <strong>milliseconds</strong> &#x26; <strong>seconds</strong>.</li><li><strong>Custom format</strong> - Enter a specific time format for your output dates in the <strong>Custom format</strong> field that appears. For the complete valid format reference, see the <a href="https://github.com/maniartech/gotime/blob/master/docs/core-concepts/nites.md#complete-format-reference">gotime Nites Format Documentation</a>.</li></ul></li></ul></td><td></td></tr><tr><td><strong>This Year</strong></td><td><ul><li><strong>This Year</strong> - Select <strong>true</strong> to create a new field with the Epoch time corresponding to the previous day at <code>00:00:00h</code> in the selected time unit.</li><li><strong>This Year output field</strong> - Give a name to the new field.</li><li><strong>This Year timezone</strong> - Enter the required timezone (for example: <code>UTC</code>, <code>America/New_York</code>, <code>Europe/London</code>...). The default value is <code>UTC</code>.</li><li><p><strong>Output type</strong> - Choose the type of your output dates:</p><ul><li><strong>Unix timestamp</strong> - This is the default value. Choose the required time unit in the <strong>This Year time unit</strong> parameter that appears. The available time units are <strong>nanoseconds</strong>, <strong>microseconds</strong>, <strong>milliseconds</strong> &#x26; <strong>seconds</strong>.</li><li><strong>Custom format</strong> - Enter a specific time format for your output dates in the <strong>Custom format</strong> field that appears. For the complete valid format reference, see the <a href="https://github.com/maniartech/gotime/blob/master/docs/core-concepts/nites.md#complete-format-reference">gotime Nites Format Documentation</a>.</li></ul></li></ul></td><td></td></tr><tr><td><strong>This Month</strong></td><td><ul><li><strong>This Month</strong> - Select <strong>true</strong> to create a new field with the Epoch time corresponding to the previous day at <code>00:00:00h</code> in the selected time unit.</li><li><strong>This Month output field</strong> - Give a name to the new field.</li><li><strong>This Month timezone</strong> - Enter the required timezone (for example: <code>UTC</code>, <code>America/New_York</code>, <code>Europe/London</code>...). The default value is <code>UTC</code>.</li><li><p><strong>Output type</strong> - Choose the type of your output dates:</p><ul><li><strong>Unix timestamp</strong> - This is the default value. Choose the required time unit in the <strong>This Month time unit</strong> parameter that appears. The available time units are <strong>nanoseconds</strong>, <strong>microseconds</strong>, <strong>milliseconds</strong> &#x26; <strong>seconds</strong>.</li><li><strong>Custom format</strong> - Enter a specific time format for your output dates in the <strong>Custom format</strong> field that appears. For the complete valid format reference, see the <a href="https://github.com/maniartech/gotime/blob/master/docs/core-concepts/nites.md#complete-format-reference">gotime Nites Format Documentation</a>.</li></ul></li></ul></td><td></td></tr><tr><td><strong>This Week</strong></td><td><ul><li><strong>This Week</strong> - Select <strong>true</strong> to create a new field with the Epoch time corresponding to the previous day at <code>00:00:00h</code> in the selected time unit.</li><li><strong>This Week output field</strong> - Give a name to the new field.</li><li><strong>This Week timezone</strong> - Enter the required timezone (for example: <code>UTC</code>, <code>America/New_York</code>, <code>Europe/London</code>...). The default value is <code>UTC</code>.</li><li><p><strong>Output type</strong> - Choose the type of your output dates:</p><ul><li><strong>Unix timestamp</strong> - This is the default value. Choose the required time unit in the <strong>This Week time unit</strong> parameter that appears. The available time units are <strong>nanoseconds</strong>, <strong>microseconds</strong>, <strong>milliseconds</strong> &#x26; <strong>seconds</strong>.</li><li><strong>Custom format</strong> - Enter a specific time format for your output dates in the <strong>Custom format</strong> field that appears. For the complete valid format reference, see the <a href="https://github.com/maniartech/gotime/blob/master/docs/core-concepts/nites.md#complete-format-reference">gotime Nites Format Documentation</a>.</li></ul></li></ul></td><td></td></tr><tr><td><strong>Random number</strong></td><td><ul><li><strong>Random number</strong> - Select <strong>true</strong> to create a new field with a random value.</li><li><strong>Random output field</strong> - Give a name to the new field.</li></ul></td><td></td></tr><tr><td><strong>UUID v4</strong></td><td>Select <strong>True</strong> to enable and enter a name for the <strong>UUID v4 output field</strong>.</td><td></td></tr><tr><td><strong>Custom field</strong></td><td><ul><li><strong>Allow custom field</strong> - Select <strong>true</strong> to create a new field with a custom value.</li><li><strong>New custom field name</strong> - Give a name to the new field.</li><li><strong>Custom field value</strong> - Set the value you want to add in the new field.</li><li><strong>Custom field data type</strong> - Choose the data type of the new field between <strong>integer</strong>, <strong>boolean</strong>, <strong>float</strong> or <strong>string</strong>.</li></ul></td><td></td></tr></tbody></table>
{% endstep %}

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

## Example

Imagine we want to add a couple of new fields to our events. We want a new field that indicates the current Epoch time and another that adds the string `Test` in each event. To do it:

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

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

<table><thead><tr><th width="198">Operation</th><th>Parameters</th><th data-hidden></th></tr></thead><tbody><tr><td><strong>Now</strong></td><td><ul><li><strong>Now</strong> - Set it to <strong>true</strong>.</li><li><strong>Now output field</strong> - We're naming the new field <code>Now</code>.</li><li><strong>Now time unit</strong> - Choose <strong>seconds</strong>.</li></ul></td><td></td></tr><tr><td><strong>Custom field</strong></td><td><ul><li><strong>Allow custom field</strong> - Set it to <strong>true</strong>.</li><li><strong>New custom field name</strong> - We're naming the new field <code>Custom</code>.</li><li><strong>Custom field value</strong> - Enter <code>Test</code>.</li><li><strong>Custom field data type</strong> - Choose <strong>string</strong>.</li></ul></td><td></td></tr></tbody></table>
{% endstep %}

{% step %}
Left the rest of the parameters as default and 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 %}
