# Field Generator

{% hint style="info" %}
See the changelog of this Action type [here](/actions/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 ](/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 **Field Generator** in the **Actions** tab (under the **Advanced** group) and drag it onto the canvas. Link it to the required [Listener](/the-workspace/listeners.md) and [Data sink](/the-workspace/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><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><mark style="color:red;"><strong>*</strong></mark> - Give a name to the new field.</li><li><strong>Now timezone</strong><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> - Give a name to the new field.</li><li><strong>Today timezone</strong><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> - Give a name to the new field.</li><li><strong>Yesterday timezone</strong><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> - Give a name to the new field.</li><li><strong>This Year timezone</strong><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> - Give a name to the new field.</li><li><strong>This Month timezone</strong><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> - Give a name to the new field.</li><li><strong>This Week timezone</strong><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> 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><mark style="color:red;"><strong>*</strong></mark> - 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><mark style="color:red;"><strong>*</strong></mark> </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><mark style="color:red;"><strong>*</strong></mark> - Give a name to the new field.</li><li><strong>Custom field value</strong><mark style="color:red;"><strong>*</strong></mark> - Set the value you want to add in the new field.</li><li><strong>Custom field data type</strong><mark style="color:red;"><strong>*</strong></mark> - 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 %}

This is how your data will be transformed with the new fields:

<figure><img src="/files/cbtZltcEcljfJPTvjI3m" 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/field-generator.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.
