# Data Mapping and Env Variables

**Env Variables** can be used for environment variables...

* ... e.g. an endpoint for the REST Helper, which first is set to the **development** endpoint and can then later be changed to the **production** endpoint,
* ... to create mappings, e.g. for IDs from one system to IDs to another system,&#x20;
* ... or to save input used in multiple actions, e.g. a list of IDs.

{% hint style="info" %}
Env Variables can be applied in **Flows** and **Insights**. They don't work in Transformations.
{% endhint %}

## Custom user-created Env Variables

You can create as many Env Variables (mappings) as you wish under the menu **Settings > EnvVariables**. Env variables can range from:

* String: `"hallo123"`
* List: `["Frankfurt", "Muenchen", "New York"]`
* JSON object: `{"Germany" : "DE", "Spain" : "ES"}`
* Nested JSON object: `{"countries": {"Germany" : "DE", "Spain" : "ES"}, "states": {"California": "CA"}}`

JSON objects are the most common and are the preferred format for mappings. You can use our table view for editing those mappings:

![Table View](https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48091872698/original/EkoiMva3nzjMRXj4REieogxD31ZGf36fHg.png?1615448872)

This table generates the underlying JSON object of the Env Variable, which you can see by switching to *Advanced view*. The *Value Type* can be either *Text* or *Number and others*; if it is *Text*, the value will be put into quotation marks, otherwise, no quotation marks are used:

```javascript
{
  "firstName": "Example",
  "lastName": "Name",
  "age": 35
}
```

You can add new entries to the JSON object with the *Add line* button. When entering the key, the table checks for duplicate keys and you have to remove one of the duplicate keys in order to make any other changes or save the Env Variable:

![Duplicate Key](https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48091878744/original/igUHQzMFAjuSpJdKAjSQVo9O15NyrCJhYQ.png?1615450577)

## System generated Env Variables

The below Env Variables are always available in Flows and Insights and generated by the system. They are not available on Transformations:

* **di\_user\_email** - user email as a string "<example.user@myemail.com>"
* **di\_user\_name** - user email as a string "Example User"

## Using Env Variables

You can use Env Variables in Flows and Insights with Jinja syntax: Simply put the Env Variable name into `{{ }}`, e.g.: `{{ country_to_country_codes }}`, this will then be dynamically replaced by the underlying Env Variable during Flow or Insight execution.

### Using Mappings in Flows

In order to use the mapping as such in a Flow, you can use the following syntax to search the mapping for the given key and return the corresponding values:

`{{ country_to_country_codes[dic1.country_name] }}`

If `dic1.country_name` is Italy, the Jinja would be outputted as `IT` during Flow execution.

### Using Mappings in Insights

To use the mapping in the same way in an Insight use the following syntax:

{% tabs %}
{% tab title="Jinja2" %}

```python
{{
    generate_array_lookup_sql(
        lookup_table=country_to_country_codes,
        value_column="country_name"
    )
}}
```

{% endtab %}
{% endtabs %}

1. `generate_array_lookup_sql` is the function name
2. For the `lookup_table` parameter insert the Env Variable name
3. For the `value_column` parameter insert the column name of your query, which should be used to search the mapping for the given key
