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 is configured to run a given script on the incoming payload.

  • Transform scripts. A script transform function is added to a field mapping (in the map shape) - 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) are more efficient than transform scripts.

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

Last updated