Skip to main content

Script

Runs a script on the value, for anything the other transforms don't cover. The script reads the value as input and its last expression becomes the new value:

1
// Turn "news, sport , culture" into a list of trimmed tags.
2
const tags = input.split(",").map((tag) => tag.trim());
3
tags.filter((tag) => tag.length > 0);

A top-level return is a syntax error, so the script ends with the expression itself, as the second line above does. It runs in the same sandbox as a Script action, under the same ceilings, and the other transforms are the first choice where one does the job, since a mapping that ends in a Script has no type the variable picker can show.

The Script transform reference describes each field, in the same words its Guide icon shows in the tool.

Where the script comes from​

An Inline script is written on the transform, and checked for syntax errors as you type. Under it, Insert from Scripts… copies a saved script's code in, and Save to Scripts… saves what is here as a new saved script, for a transform worth sharing. A Saved script is a live reference: the transform runs whatever the saved script holds when the mapping is resolved, so an edit in the catalog reaches every transform that references it. The transform shows the chosen script's code read-only, with a link to edit it in the catalog.

A transform has no Runtime source, since it receives a value and nothing else, so there is nothing for a source that reads another value to bind to. Esca doesn't offer to write a transform's script either; have Esca write the script on a Script step, save it to the catalog, and reference it here.

What the script can read​

One value is available: input, the value so far, which is the mapping's source or what the transform before this one produced. A value that resolved to nothing is null. payload is not available here, and nor is the dari content SDK; a transform that needs the step before's output takes it through the mapping's source, and one that needs to build content belongs on a Script step.

The value of the script's last expression is the mapping's value from here on, handed to the next transform or, from the last transform, to the step. console.log() and its siblings are captured as entries in the step's log, each labeled with its mapping and transform, such as Input · headline › Script, and shown under the transform in the mapping's trace; see Logging.

What later steps see​

A script can return anything, so a mapping that ends in a Script is offered to later steps without a type: they can take its value whole, but not pick inside it. Where later steps need to reach a field of what the script returns, end the mapping with an Extract Path for that field, or move the work to a Script step with an Output Type declared.

When it fails​

A script that was never written, a saved script that has been deleted or isn't available in this site, a syntax error, an error the script throws, or a ceiling crossed fails the step, and the mapping's trace shows the Script transform as the one that failed, with the message. An input mapping fails the step before it runs; an output mapping fails it once its work is done. Neither is retried. See When a script fails and When a transform fails.

Limits​

The sandbox and its ceilings are the same wherever a script runs, and are listed under Limits.

  • Scripting: where scripts run, and what each place gives them.
  • Script action: a script as a step of its own, with payload, dari and Esca's help.
  • Scripts: the catalog a Saved script comes from.

Was this page helpful?

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