# Prefix transform function

## Introduction

The `prefix` transform function is used to add characters to the start of a given string field. For example:

```
[
    {"SKU": "RED001"},
    {"SKU": "RED002"},
    {"SKU": "BLUE001"},
    {"SKU": "BLUE002"},
    {"SKU": "GREEN001"},
    {"SKU": "GREEN002"}
]
```

...might become:

```
[
    {"SKU": "AW25-RED001"},
    {"SKU": "AW25-RED002"},
    {"SKU": "AW25-BLUE001"},
    {"SKU": "AW25-BLUE002"},
    {"SKU": "AW25-GREEN001"},
    {"SKU": "AW25-GREEN002"}
]
```

## Adding a prefix transform

{% stepper %}
{% step %}
**Edit map shape settings**

In your process flow, access settings for your map shape. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FHafDDUEOghD7GbogBifI%2Fprefix%20transform%201.png?alt=media&#x26;token=18c550ac-1dac-48e6-9e85-10d7aec244a2" alt="" width="349"><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Access transforms for the required mapping**

Locate the mapping rule that you want to update (or add a new mapping rule), then click the `transform` button. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FrBVuaWt2Ong5301UK6Bv%2Fprefix%20transform%202.png?alt=media&#x26;token=c7016315-db26-4864-a5ce-5b54ae0946e8" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Add a new transform**&#x20;

Click the `add transform` button. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FpdMmcEhWKwZICL5DAFqJ%2Fprefix%20transform%203.png?alt=media&#x26;token=993fa912-e1c8-4ca9-996c-263e5366cef3" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Select the prefix transform function**&#x20;

Click in the `name` field to access a list of all available transform functions, then select `prefix` from the `string` category. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FeEOGtxpxaZsyGUoRJ7Ms%2Fprefix%20transform%204.png?alt=media&#x26;token=8e415577-1139-4f37-9979-5f3b3d3412a1" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Enter your required prefix**

In the `prefix` field, enter the characters that you want to append to the start of any source values for the source field. For example:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FPUivzXYbJdCJhPm7F9wx%2Fprefix%20transform%205.png?alt=media&#x26;token=a99850a6-ec1e-4ed2-9358-a06ab94cf193" alt=""><figcaption></figcaption></figure></div>

You can enter static text and/or [flow/meta variables](#using-variables-in-prefix-transform-values). &#x20;
{% endstep %}

{% step %}
**Confirm the source field to be transformed**

Click the `add field` button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FAtHgY370mso6w6vIauei%2Fprefix%20transform%206.png?alt=media&#x26;token=9c9f8399-fc4c-4f9b-8b7d-bbc9965795e1" alt=""><figcaption></figcaption></figure></div>

...then click in `source fields` and select the source field to be used for this transform:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FbG9bBCDQrZQbkzCev1iY%2Fprefix%20transform%207.png?alt=media&#x26;token=9d289cf7-b8ad-4c39-96aa-6ea967fb19a2" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
**Confirm transform settings**

Accept your changes (twice), then save the transform.&#x20;
{% endstep %}
{% endstepper %}

## Using variables in prefix transform values

You can include [flow](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables) or [meta](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/metadata-variables) variables when defining prefix values. Some examples are shown below.&#x20;

<table data-full-width="false"><thead><tr><th width="281.30859375">Prefix value</th><th width="144.4765625">Variable value</th><th width="132.83984375">Incoming value</th><th>Output value</th></tr></thead><tbody><tr><td><pre><code>AW25-
</code></pre></td><td>N/A</td><td><pre><code>RED001
</code></pre></td><td><pre><code>AW25-RED001
</code></pre></td></tr><tr><td><pre><code>{{flow.variables.season}} 
</code></pre></td><td><code>season</code> : <code>AW25</code></td><td><pre><code>RED001
</code></pre></td><td><pre><code>AW25RED001
</code></pre></td></tr><tr><td><pre><code>{{flow.variables.season}}-
</code></pre></td><td><code>season</code> : <code>AW25</code></td><td><pre><code>RED001
</code></pre></td><td><pre><code>AW25-RED001
</code></pre></td></tr><tr><td><pre><code>[[meta.month]] 
</code></pre></td><td><code>month</code> : <code>JUNE</code></td><td><pre><code>RED001
</code></pre></td><td><pre><code>JUNERED001
</code></pre></td></tr><tr><td><pre><code>[[meta.month]]-
</code></pre></td><td><code>month</code> : <code>JUNE</code></td><td><pre><code>RED001
</code></pre></td><td><pre><code>JUNE-RED001
</code></pre></td></tr></tbody></table>

{% hint style="info" %}
Currently, it's not possible to combine `flow` and `meta` variables in a prefix value. This is a known issue to be addressed in a future release.&#x20;
{% endhint %}
