> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/patchworks-services/working-with-services/field-mappings-and-transformations-services/field-transformations-services/using-a-custom-script-in-field-transformations-services.md).

# Using a custom script in field transformations (services)

## Introduction

This page explains how to apply a custom script as a transform function for service field mappings.

{% hint style="danger" %}
If this is the first time you are using this script, you are strongly advised to work with a test service and ensure everything syncs as expected before applying to live services.&#x20;

In Patchworks, a test service can be created by defining **test** (rather than **live**) source and destination connectors which point to sandbox URLs for the associated systems.
{% endhint %}

## The steps

**Step 1**\
Access the [services list](/product-documentation/patchworks-services/working-with-services/the-services-list.md):

<figure><img src="/files/yr8fjq0Kzt6Vpm41Tum4" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Please see [accessing services](/product-documentation/patchworks-services/working-with-services/accessing-services.md) if you're not sure how to get to this point.
{% endhint %}

**Step 2**\
Click on the service that you wish to update:

<figure><img src="/files/2TFfGupTe9SKcfNSu9uU" alt=""><figcaption></figcaption></figure>

**Step 3**\
Click the **mapping** tab:

<figure><img src="/files/FQFur60wWnnKeQ39V7fA" alt=""><figcaption></figcaption></figure>

...existing field mappings are displayed:

<figure><img src="/files/ZJkLBCWXz7nqoUm6OTxB" alt=""><figcaption></figcaption></figure>

**Step 4**\
Click the mapping entry that you wish to update with a new transform (or add a new mapping row):

<figure><img src="/files/T8PlqypFMVGq4su7Z9J5" alt=""><figcaption></figcaption></figure>

**Step 5**\
Click the **edit** option associated with the expanded mapping entry:

<figure><img src="/files/hUF77uuxJgmgyAKEDjsL" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/U8bSSDBx4IRr3WJdwu2R" alt=""><figcaption></figcaption></figure>

...the **transformation editor** is displayed, with a visual representation of the source and destination points for the mapping, together with an **add new function** option to define the required transformation between these two points:

<figure><img src="/files/sJtg9qR4fkaXhFGMlB2G" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
A maximum of 15 custom scripts can be added to a single transform.
{% endhint %}

**Step 7**\
Click the **add new function** option:

<figure><img src="/files/r6cSIi2pC3BQfd6IiDlN" alt=""><figcaption></figcaption></figure>

...**function settings** are displayed:

<figure><img src="/files/px5FjU24e9TZ3A7MZzW4" alt=""><figcaption></figcaption></figure>

**Step 8**\
Click in the **function name** field and select **run custom script** from the dropdown list:

<figure><img src="/files/1i3G0cRrC40q816HY68C" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The **run custom script** option is available for all data types except **float**.
{% endhint %}

...the **transformation editor** page updates and a new **select custom script** field is displayed:

<figure><img src="/files/1BqfSRHwWk7sSADYXGIw" alt=""><figcaption></figcaption></figure>

**Step 9**\
Click in the **select custom script** field to show a list of all available custom scripts, then choose the required entry for this mapping:

<figure><img src="/files/c48WGEwtG6S1uC7T5LnW" alt=""><figcaption></figcaption></figure>

...the **transformation editor** page updates so the code and any variable fields for the selected script are shown:

<figure><img src="/files/0YukYFbHErwldMuwfpvk" alt=""><figcaption></figcaption></figure>

...scroll down to view the code associated with this script:

<figure><img src="/files/htaR3K5Y9tXvl21M5VMh" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can't change custom script code here in the **transformation editor**. However, options are available so you can make changes to the original custom script, quickly and easily:\
\ <img src="/files/mGlvDycu9VcAUkTa5EGE" alt="" data-size="original">

Click the **manage custom script** link in the info box (see **1** above) to open the custom script in edit mode, in a new browser tab. There, you can make changes and save the script - then return to the **transformation editor** and click the **refresh** icon (see 2 above) to refresh the code.&#x20;
{% endhint %}

**Step 10**\
Update variable fields as required. Click in a variable field and choose either **custom value** (then enter a static value to the right):&#x20;

<figure><img src="/files/Ll3cCb0yDpHU1uEyNKep" alt=""><figcaption></figcaption></figure>

...or select **source mapping field** (then select the required source mapping field to the right):

<figure><img src="/files/USpcupReGabteO5QfvCS" alt=""><figcaption></figcaption></figure>

**Step 11**\
Click the **save function** button:

<figure><img src="/files/T3RoDi9VHRvKGUGAwU4O" alt=""><figcaption></figcaption></figure>

...the **transformation editor** updates and your new function is displayed in the visual representation. From here, you can choose to add another function, or **save transformation**:

<figure><img src="/files/TQhqNKU2JiJyfX5LX3Ri" alt=""><figcaption><p><br></p></figcaption></figure>

...you are returned to the mapping page, which now shows a transformation for the row you've been working on:

<figure><img src="/files/4qT8bqVAAC3ivbBO8pD7" alt=""><figcaption></figcaption></figure>

**Step 12**\
Repeat these steps as required for any other mapping entries.&#x20;
