Skip to main content

Script

Configuration → Automation → a workflow → Designer → Script node

A Script node runs a short piece of JavaScript and maps whatever it returns into fields the rest of the workflow can use. It is the most flexible node in the Toolbox, for transformations a Formula node's built-in functions cannot cover. Like Delay, List, and Formula, it has a single path in and a single path out.

Adding a Script Node​

  1. Open a workflow's Designer. Configuration → Automation → a workflow. See Workflow Builder.
  2. Drag the Script card from the Toolbox onto the canvas. Script sits last in the Toolbox, marked with a teal code icon and the subtitle Run JS script and map responses.
  3. Connect an earlier node's output into the Script node's top handle, and its own output into whatever should run next.

Designer canvas showing a Trigger node connected to an Action node, which connects onward to a Script node placed clear of both, with its edit and delete icons visible

A Script node connected after an Action step, with a single top and bottom connection point.

Opening the Script Editor​

  1. Click the Script node to select it. Reveals its edit and delete icons.
  2. Click the edit icon. Opens the Edit script Node panel, with a Label field above a Script Code section and a Response Mapping section below it.

Edit script Node panel showing Label set to Script, a Script Code section with an empty code editor, and the start of a Response Mapping section below it

The Edit script Node panel in its default state: an empty Script Code editor above an empty Response Mapping section.

Writing the Script​

Script Code is a full code editor, Monaco, the same editor that powers Visual Studio Code, not a plain text box. It accepts real JavaScript, including a return statement for whatever value the script should hand off.

  1. Write JavaScript directly into the editor. Standard syntax highlighting, line numbers, and bracket matching all work as expected.
  2. Type a few letters of an upstream field's name to reference it, then pick the matching suggestion. For example, typing casetype surfaces entries like "Get Record Service Cases By ID - Case Type", each labeled by the node and field it comes from.
  3. Accept the suggestion to insert the real reference syntax. Inserts (nodeId.fieldName), for example (action_3.caseType), where fieldName is the field's label converted to camelCase.

Script Code editor with Ctrl+Space pressed on an empty line, showing a long autocomplete list of generic JavaScript and browser globals such as AbortController, AbortSignal, AbstractRange, and Array

Ctrl+Space on an empty editor: generic JavaScript globals only, with nothing typed yet to match against.

note

Autocomplete does list real workflow fields, not just JavaScript globals. It only surfaces them once matching letters are typed first.

Mapping the Response​

Response Mapping uses the same pattern seen elsewhere in the platform: paste a sample of the JSON the script will return, and a schema is generated automatically from it.

  1. Paste a sample JSON response into JSON Input, or save the script directly. A sample can be pasted by hand, but it also auto-populates from the script's own return statement once saved, with no manual step needed.
  2. Review the generated Schema Editor below it. Lists each detected field, its Data Type, and an editable Field Type, with a delete action per field.

Edit script Node panel showing Script Code containing return total: 1 + 1, JSON Input containing total: 2, and a Schema Editor below reporting 1 field detected, with a row for the field total, data type number, field type Number

A complete example: the script returns total, the JSON Input sample confirms its shape, and Schema Editor detects one field, total, typed as a number.

Edit script Node dialog showing a longer script that looks up a supervisor by Case Type, reading (action_3.caseType), with Response Mapping below showing a JSON Input auto-populated from the script's return statement and 3 fields detected in the Schema Editor

A real example from a live workflow: Case Type read via (action_3.caseType), and a 3-field schema generated automatically from the return statement, with no JSON pasted by hand.

info

Field Types also get inferred from field names, not just their JSON data type. supervisorEmail and supervisorPhone auto-typed as Email and PhoneNumber, not plain string.

Field Type Options​

Each detected field's Field Type can be changed manually in the Schema Editor, independent of the data type the sample JSON implied.

Field Type
string
number
boolean
tip

This same "paste a sample, get a schema" pattern also appears on Webhook creation and on a CRM External Module's Res Schema; learning it once here carries over directly to both.