
This article presents inserts that can be used while creating [transformation rules](/docs/automation/data-transformation-and-imports/creating-data-transformation).


<div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

If you use Visual Studio Code as your editor, you can use code snippets to speed up working with inserts.  
You can find the snippets in our Github repository: [https://github.com/Synerise/jinja-code-snippet](https://github.com/Synerise/jinja-code-snippet)

</div></div></div>


## Change values

You can replace the value in a column with another value.

To get a value from the file, use the following snippet:

<pre><code class="language-jinja">root['columnName']</code></pre>


### Change current value

The following snippet replaces the value of `paymentInfo`:
- if the value is `cash`, it is replaced with `POS`
- any other value is replaced with `WEB_DESKTOP`


  <pre><code class="language-jinja">{%- if root['paymentInfo'] == 'cash' -%}POS{%- else -%}WEB_DESKTOP{%- endif -%}</code></pre>



### Conditionally keep current value

The following snippet keeps `cash` as the value of `paymentInfo`, but replaces any other value with `WEB_DESKTOP`


<pre><code class="language-jinja">{%- if root['paymentInfo'] == 'cash' -%}{{root['paymentInfo']}}{%- else -%}WEB_DESKTOP{%- endif -%}</code></pre>


### Combine conditions

The following snippet replaces the value of `paymentInfo`:
- `cash` is replaced with `POS`
- `online` is replaced with `WEB_DESKTOP`
- any other value is replaced with `UNKNOWN`


  <pre><code class="language-jinja">{%- if root['paymentInfo'] == 'cash' -%}POS{%- elif root['paymentInfo'] == 'online' -%}WEB_DESKTOP{%- else -%}UNKNOWN{%- endif -%}</code></pre>


### Replace string
The following snippet takes the value of `g:sale_price` and replaces " USD" with an empty string, for example "256 USD" becomes "256".


<pre><code class="language-jinja">{{ root["g:sale_price"]|replace(" USD", "") }}</code></pre>


## Fill in empty values

If a cell has no value (is empty), you can insert a value.

The following snippet replaces a missing value of `paymentInfo` with `foo`


<pre><code class="language-jinja">{%- if not root['paymentInfo'] -%}foo{%- else -%}{{root['paymentInfo']}}{%- endif -%}</code></pre>


## Event salt

The event salt is a UUID generated on the basis of unique combination of at least two parameters. This allows you to avoid duplicating an event entry in the database if it is imported more than once.

1. Select two or more parameters whose combination is unique.  
    For example, you can use `orderID` and `eventTimestamp`. Even if one of them repeats for some reason, the chances of both being identical between two events are practically zero.
2. Add an `eventSalt` column.
3. In the `eventSalt` column, add the following insert (example according to step 1):  
    
   <pre><code class="language-jinja">{{root.orderId}}{{root.eventTimestamp}}</code></pre>


    where `orderId` and `eventTimestamp` are column names.

**Result:**
When the import is processed, the value combination in the `eventSalt` column is calculated into a UUID that is always the same. When other imports are performed and that UUID already exists in the database, the event is not imported as a duplicate.

## Calculate revenue

If the file does not have a column that calculates the total value of an imported transaction, add a `revenue.amount` and `value.amount` column and use Jinjava to perform that calculation.


<div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

All items from the transaction must be contained in rows that immediately follow each other. Transactions are recognized by `orderId` and products are recognized by `sku`.
<figure><img src="/api/docs/image/54176ad07f146575310749eba44b7c2f42c1b327/developers/inserts/_gfx/order-example.png" class="medium" alt="Examples of correct and incorrect order of items in an import"><figcaption>Example of correct and incorrect grouping of items according to the order they were included in</figcaption></figure>

</div></div></div>


The following code uses the values from the `productQuantityProduct` and `finalUnitPriceAmount` to calculate the total value of an order.  
The actual code **must not** include any line breaks, the example uses them for better readability.


<pre><code class="language-jinja">{% set line_sums = [0] %}
{%- for prod in root.products -%}
{%- if line_sums.append(prod["productQuantity"]|int*prod["finalUnitPriceAmount"]|replace(",", ".")|float) -%}
{%- endif -%}
{%- endfor -%}
{{ line_sums|sum }}</code></pre>
