# Using a payload-level custom script in services

## Introduction

This page explains how to [associate a payload-level custom script with a service](#associating-a-payload-level-script-with-a-service), then [run the service and check input and output payloads](#running-the-service-and-checking-payloads).

{% 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 %}

## Associating a payload-level script with a service

**Step 1**\
Use the **services** option to access an existing service that you'd like to [update](/product-documentation/patchworks-services/working-with-services/updating-a-service.md), or [add a new service](/product-documentation/patchworks-services/working-with-services/adding-a-patchworks-service.md): \
\
&#x20;![](/files/H731KDA1t9WJeqOaFYkl)

**Step 2**\
If at least one **payload-level** custom script has been added, a **payload script** tab is available - select it:

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

**Step 3**\
Click the **select custom script** field and choose the script that you wish to associate with this service - for example:

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

**Step 4**\
Details for the selected script are displayed:

<figure><img src="/files/6uIPfsAqW55UDP1xG94e" alt=""><figcaption></figcaption></figure>

You don't need to do anything here - everything is ready to go. However, if you wish to update the script, click the **modify this script** button to edit the script in the [manage custom scripts](broken://pages/t4yS4AdiuZFgXqgJzizY) area. &#x20;

{% hint style="info" %}
If a script is associated with a service and subsequently edited and saved, changes are applied to associated services automatically.
{% endhint %}

**Step 5**\
Use the **add script to service** button to apply changes.&#x20;

## Running the service & checking payloads

**Step 1**\
Select the **run service** tab:

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

**Step 2**\
Scroll down to the **service options** section and toggle on the **store custom script payloads** setting: &#x20;

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

**Step 3**\
Set all other options as required and run the service:

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

**Step 4**\
As the service runs, custom script activity is displayed in the the **custom scripts logs** section of the service log - for example:

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

**Step 5**\
When the service run is complete and you opted to download custom script payloads, you can download these files using buttons in the custom script payload panel:

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

{% hint style="info" %}
If you forget to download files at this point, a download link will be available in the [service log](/product-documentation/patchworks-services/reporting-and-logging/service-sync-logs.md) for 24 hours. For example:

![](/files/JHa19ucs8D4FK58I1kaG)
{% endhint %}

{% hint style="info" %}
When a **payload-level** custom script is associated with a service, an **edit script** option is available on the service canvas. For example:

![](/files/PS3PhUqIOydALeeJ6NaV)
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.wearepatchworks.com/product-documentation/patchworks-services/working-with-services/updating-a-service/using-a-payload-level-custom-script-in-services.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
