# Field transformations (services)

## Introduction

**Field transformations** can be defined to change the value of data pulled from a source system before it is pushed to a destination system. A **transformation** is comprised of one or more **functions**.

This page explains how to [add a new transformation](#adding-a-new-transformation) for a field mapping, and [how to remove functions and transformations](#deleting-an-existing-function-or-transformation).&#x20;

## Adding a new transformation

To add a new transformation for a field mapping, you start by adding a new transformation and then build the required functions. To do this, follow the steps below:

**Step 1**\
[Access the required service ](https://doc.wearepatchworks.com/product-documentation/patchworks-services/working-with-services/accessing-services)and select the **mappings** tab:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/XT0HHUH9ZWiIiRYkaAlN/select%20mapping%20tab.png" alt=""><figcaption></figcaption></figure>

**Step 2**\
The **field mapping** page is displayed with mappings organised in logical categories, based on the **destination** connector:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/504IWmhWpQNe5CfVAEFL/field%20mapping%20page.png" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If a transformation has been applied to a field mapping already, it is displayed with a transformation icon:\ <img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/pEGpFXTXcuq3ty1L0pi6/transform%20already%20present.png" alt="" data-size="original">&#x20;
{% endhint %}

**Step 3**\
Find the mapping that you wish to update with a transformation, then click anywhere in the row to expand details and choose the **edit** option:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/uWDijIdwvdP5Lzp7BjRH/field%20transform%20journey.png" alt=""><figcaption></figcaption></figure>

...the field mapping is displayed in edit mode:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/QETC4sbZXyFGrBkpBE6X/field%20mapping%20in%20edit%20mode.png" alt=""><figcaption></figcaption></figure>

**Step 4**\
Click the **add transformation** button:

![](https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/q6T4IsozfT3gllk8wWWM/add%20transform%20option%20selected.png)

...the **transformation editor** is displayed:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/QXyCnCCFnpYFsnqRzTiv/transformation%20editor%20page%20-%20no%20functions%20added.png" alt=""><figcaption></figcaption></figure>

**Step 5**\
Click the **add new function** button:\
\
![](https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/G6ay9C9kD91HcyYc0F1O/add%20new%20function%20selected.png)

\
...settings for the new function are shown: &#x20;

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/YG6nG0pcCjatGhHqrEx8/add%20function%20-%20settings.png" alt=""><figcaption></figcaption></figure>

**Step 6**\
Click in the **function name** field and select the type of function that you'd like to add:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/mHIGKzoms2Yk5EQORsyb/select%20function%20type.png" alt=""><figcaption></figcaption></figure>

**Step 7**\
Depending on the type of function you select, additional fields are displayed for you to complete. Update these as required and click the **save function** button:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/xF5fxMsYRyDO0jeJzwql/save%20function.png" alt=""><figcaption></figcaption></figure>

...the new function is added to the **transformation editor**:\
\
![](https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/uLCNIwvwCHIDdrm0cnJr/function%20added%20to%20transform%20editor%20-%20cropped.png)

{% hint style="info" %}
If your transform uses a **type** conversion (for example, converting a string type to a date type) and your transformed data type does not match the destination, you will need to add a **convert to function** before the function can be saved.
{% endhint %}

**Step 8**\
Repeat these steps to add any more functions that you need. When you're ready, click the **save transformation** button (at the bottom of the **transformation editor** page):\
\
![](https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/EHH3QyjK1uw5oYoIIyEK/save%20transform.png)

...you'll exit back to the field mapping in edit mode:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/54gITwFD3VHJfZfGZPBY/transformation%20added%20-%20back%20to%20mapping%20.png" alt=""><figcaption></figcaption></figure>

**Step 9**\
Click the **done** button to confirm changes:\
\
![](https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/M6gxNL2HSqFskeLT6PC2/mapping%20edit%20done.png)

## Deleting an existing function or transformation

**Step 1**\
Follow steps [1 to 3 above](#adding-a-new-transformation) to edit the required field mapping.  The mapping is shown in edit mode and - if transformations are present - you will see an **edit transformation** button:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/TPbzAFgOkntz3utfEhoP/transformation%20added%20-%20edit%20button%20available.png" alt=""><figcaption></figcaption></figure>

**Step 2**\
Select the **edit transformation** button to open the **transformation editor**. Here, any existing functions for the transformation are shown:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/DNGlvX7FTThWjQv1h4B8/transformation%20editor%20-%20function%20present.png" alt=""><figcaption></figcaption></figure>

**Step 3**\
Select the function that you wish to remove - settings for this function are displayed in the right-hand panel:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/08ivjse3G5MuQZHstdSb/select%20existing%20function.png" alt=""><figcaption></figcaption></figure>

**Step 4**\
Click the **delete function** button:

<figure><img src="https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/gcrGKcxVbowxKqIprP8A/delete%20function%202.png" alt=""><figcaption></figcaption></figure>

**Step 5**\
When prompted, confirm that you wish to proceed with this operation - the function is removed.

**Step 6**\
Keep in mind that a transformation may contain multiple functions. If no other functions are defined for this transformation, click the **delete transformation** button:\
\
![](https://content.gitbook.com/content/5mpqoXPMbUuPa8JpCLWe/blobs/B8uvRN31Jwt53uUbyOLm/delete%20transformation%20button%20selected.png)

...if other functions are defined for this transformation, click the **save** transformation button.<br>
