Skip to main content

Script

Runs a short script in a sandbox and hands its result to the rest of the flow. Reach for it to reshape data between two steps—flattening a response, filtering a list, computing a value—when no purpose-built action fits.

Fields

FieldDescription
LanguageThe language the script is written in. Choosing JavaScript reveals its Script field, holding the source.
ScriptThe source code. It is checked for syntax errors as you type, and the field carries a note summarizing the sandbox and the variables available.
Output TypeThe shape of the value the script returns, so later steps can reference its fields by name.
Auto-generate Output TypeInfer the output type from what the script actually returned on the automation's last finished run, instead of declaring it by hand. Disappears once an output type exists. Checking it before the automation has ever run leaves the box checked, so the next save after a run picks it up.

The script is needed to run, not to save. Leave it empty and the step shows a needs-attention note rather than blocking the save, so you can lay out a flow before writing its code—see Building automations. At run time, an empty script fails the step.

What the script can read

Two values are available:

  • payload—the output of the step immediately before this one. It is not defined at all when that step produced nothing, so a script that might run in that position should test typeof payload !== 'undefined' rather than reaching for optional chaining, which does not survive an undefined name.
  • input—the values you mapped into the step on its Input tab, reachable as input.fieldName.

The value the script returns is the step's output. That value is the last expression evaluated: a top-level return is not supported.

console.log(), console.warn(), and console.error() are captured as timestamped entries in the step's own execution log.

What later steps see

With an output type declared, later steps see its fields. A value with no fields to expose—a single number or string, a list, or an object declared with no fields—is offered whole under payload. With no declared type, the shape is unknown to later steps until the script has run at least once.

Limits

Scripts run with no access to the file system, the network, or the host. Several ceilings bound what one script may consume, because the server runs many at once and none of them should be able to slow the others down. Script steps are meant for transforming data, and the defaults sit well above what that needs.

What is limitedDefault
Time to run3 seconds
CPU time used1 second
Statements executed1,000,000
Memory held at once32 MB
Memory allocated in total, including memory the script discards as it goes192 MB
Longest single string4,194,304 characters
Largest single typed array, such as a Uint8Array1,048,576 elements
Console output captured per run64 KB
Length of the script itself262,144 characters

For scale: a script that maps and filters a 50,000-item list and re-serializes it to JSON uses roughly 250,000 statements, under a tenth of a second, and under 4 MB of memory.

Crossing a ceiling fails the step with a message naming the one you crossed, so you can tell which value is in the way. Your administrator can change any of them—the two memory ceilings and the CPU ceiling additionally depend on how the server is set up—but the message always names the ceiling that stopped the script.

If you are hitting a limit, the usual fix is to move work out of the script rather than raise the ceiling: filter a list before the script rather than inside it, or split one large script into several steps.

note

The Content Script action, which builds and edits CMS content from a script, is a different node that belongs to the Brightspot CMS integration—see Brightspot CMS.

Was this page helpful?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.