# Testing scripts

## **Introduction**

The script editor has an integrated testing panel, to the right of your code:&#x20;

<figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fs6M39bRXA2HH9GD62uJz%2Ftest%20script%201.png?alt=media&#x26;token=aca1dc00-5fb0-4846-9c3d-442c4b1d4203" alt=""><figcaption></figcaption></figure>

Here, you can enter a sample payload with (if needed by the script) sample variables and run the script in test mode.&#x20;

## **The steps**

Follow the steps below:

**Step 1**\
Move across to the `test` panel, to the right.

**Step 2**\
Add/paste a payload that can be used to test your script - 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%2FMNSBiANqkJ53JdCt7G9n%2Fscripts%205.png?alt=media&#x26;token=7577aded-22c5-44ce-b3ec-5a36c7d8f540" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 3**\
If your script references [variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/payload-variables) or [flow variables](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/dynamic-variables/flow-variables), you can also add variables for testing:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FMNSBiANqkJ53JdCt7G9n%2Fscripts%205.png?alt=media&#x26;token=7577aded-22c5-44ce-b3ec-5a36c7d8f540" alt="" width="563"><figcaption></figcaption></figure></div>

**Step 4**\
Click the `run` button:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FB45idHVMZi0cYvv5kKcr%2Fscripts%206.png?alt=media&#x26;token=3d02f0b2-b825-44ba-a3c6-724f1ca670e8" alt="" width="303"><figcaption></figcaption></figure></div>

...the script runs against your test payload and results are displayed at the end - 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%2FkxttSUngqDABDSHViHRU%2Fscripts%207.png?alt=media&#x26;token=044da821-710c-475a-aeb3-8afc127d3677" alt="" width="303"><figcaption></figcaption></figure></div>

{% hint style="info" %}
For more detailed information about a script test, you can `get logs`:

![](https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FIsn4LCUQytARt15NhIrM%2Fscripts%208a.png?alt=media\&token=b8621c72-ce2b-489e-ab05-c5f82f248dd2)\
\
...current logs are displayed:

![](https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FSG8V00haSwOyglEnUB6D%2Fscripts%208b.png?alt=media\&token=e611a845-9615-4579-8bd9-c80afd6c1312)
{% endhint %}

**Step 5**\
Keep testing the script until you're satisfied that it's working as required.&#x20;

{% hint style="warning" %}
Any time that you make a change to the script and want to test it, always `save and deploy` the code first. When you run a script, it always uses the last saved version.
{% endhint %}

Once these tests are complete, you can:

* [Apply a payload-level script to process flows via the script shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/script-shape)&#x20;
* [Apply a field-level custom script to field transformations via the map shape](https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/map-shape)&#x20;
