> 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/process-flows/building-process-flows/best-practice-for-building-process-flows/scripts-best-practice.md).

# Scripts - best practice

## Introduction

This page summarises best practice insights for for working with scripts in process flows. Keep in mind that scripts come in two 'flavours':

* Payload scripts. A [script shape ](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/script-shape.md)is configured to run a given script on the incoming payload.
* Transform scripts. A [script transform function](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/map-shape/working-with-field-transformations/available-transform-functions/other-transform-functions/script-transform-function.md) is added to a field mapping (in the [map shape](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/map-shape.md)) - this runs a given script on the associated source field before the mapping is completed.&#x20;

## One script is more efficient than multiple scripts

Generally, doing everything you can in a single script is more efficient than processing multiple scripts - it means less downtime between steps, and less chance of being caught in a queue between scripts.

There are times where deploying multiple scripts is preferable from a management perspective - for example, if you're designing generic scripts to use across multiple process flows. In this case, you trade modularity for speed, in most cases.

## Payload scripts are more efficient than transform scripts

Payload scripts (i.e. scripts run via the [script shape](/product-documentation/process-flows/building-process-flows/process-flow-shapes/advanced-shapes/script-shape.md)) are more efficient than [transform scripts](/product-documentation/process-flows/building-process-flows/process-flow-shapes/standard-shapes/map-shape/working-with-field-transformations/available-transform-functions/other-transform-functions/script-transform-function.md).

Effectively, a transform script pauses the map shape, calls the script, then merges that response and continues with the map. Multiple script transforms results in multiple pauses - similar to running multiple scripts back-to-back in the process flow itself.

## Debugging scripts

The [Patchworks script editor](/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts.md) allows you to edit scripts and test with a given payload, but for detailed debugging, we advise using an IDE with a debugger to step through the code. &#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://doc.wearepatchworks.com/product-documentation/process-flows/building-process-flows/best-practice-for-building-process-flows/scripts-best-practice.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
