# Script shape

## Introduction

If you have defined [custom scripts](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting) for use in process flows, use the `script` shape to select a script to apply at a given point in a process flow. You can use any version of a script which has been saved and deployed.

{% hint style="info" %}
A single incoming payload for [any process flow shape](https://open.gitbook.com/~site/site_dIV1g/~/revisions/9dTvdvRJIRVZQXuBMMnJ/process-flows/building-process-flows/process-flow-shapes) should not exceed 500MB.

We recommend processing multiple, smaller payloads rather than a single payload (1000 x 0.5MB payloads are more efficient than 1 x 500MB payload!).

For payloads up to 500MB, consider adding a[ flow control shape](https://open.gitbook.com/~site/site_dIV1g/~/revisions/9dTvdvRJIRVZQXuBMMnJ/process-flows/building-process-flows/process-flow-shapes/standard-shapes/flow-control-shape) to batch data into multiple, smaller payloads. Payloads exceeding 500MB should be batched at source.
{% endhint %}

## Need to know

* If a script fails it is retried three times (automatically) before a failure is given.
* A script will time out if it runs for more than 120 seconds.

## Adding a script shape

**Step 1**\
In your process flow, add the `script` shape in the usual way:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FcCB06PTygXfdd2aa6pSX%2Fadd%20script%20shape%200.png?alt=media&#x26;token=b7a0b21a-90f1-4505-915b-12a32fd57286" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 2**\
You're prompted to select an existing script:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fr21LaUy8EdSonZYGlCYc%2Fadd%20script%20shape%200a.png?alt=media&#x26;token=badc08b8-299a-49ac-865e-a3e5cab7d5af" alt="" width="375"><figcaption></figcaption></figure></div>

**Step 3**\
Select the script that you want to use at this point in the process flow:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FEyPSy6EqYLuy4sLZFoY6%2Fselect%20script%201.png?alt=media&#x26;token=08404f44-fb77-4a27-bfca-9985e14a1f4f" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
The list of available scripts includes all scripts, irrespective of whether they are deployed. If you choose a script that isn't deployed, it will be deployed the first time it's needed, when the process flow runs.&#x20;
{% endhint %}

{% hint style="info" %}
If you have lots of scripts, use the `search` field to search by name.
{% endhint %}

**Step 4**\
Select which `version` of the script to use. Unless you have a specific reason to do otherwise, we advise using the latest version of scripts. 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%2FNfic2y8NPBAbxXFQJoUg%2Fselect%20script%202.png?alt=media&#x26;token=4355f9ad-fa54-445f-87d7-f864ee792b63" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
Code is displayed in view mode. If you need to change the script, save your shape now and then use the left-hand navigation bar to access `process flows` ➤ `custom scripts`.
{% endhint %}

**Step 6**\
Save the shape:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2Fv4VAyzlYjmBPbavECbOh%2Fadd%20script%20shape%202b.png?alt=media&#x26;token=386b5088-c54f-49d6-8e22-c6b2724a6acf" alt="" width="375"><figcaption></figcaption></figure></div>

## Accessing script shape settings

To view/change the selected script for an existing **script** shape, click the associated 'cog' icon:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FwZLGA7m2sBCVXYAIgODZ%2Fscript%201.png?alt=media&#x26;token=2b9128f7-882c-4166-8ee1-45fdc3dc82a8" alt="" width="317"><figcaption></figcaption></figure></div>

From here, the existing script is displayed - you can either select a different script, or a different version of the existing script:

<div align="left"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2F4iqg22oRWSKWpfeU0MjY%2Fscript%202a.png?alt=media&#x26;token=6d62595d-a57b-4587-b69e-3e79b5db2b70" alt="" width="375"><figcaption></figcaption></figure></div>

{% hint style="info" %}
Remember that the script code can't be changed here. If you need to change the script, save your shape now and then use the left-hand navigation bar to access `process flows` ➤ `custom scripts`.
{% endhint %}
