> 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.

## 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.
