How it works
- Write the code as the body of a function and return the result, which can be any JSON value.
- The code can read the routine's variables, earlier steps' outputs, the trigger's details and inputs, all as read-only copies; secrets and the clipboard are never visible to it.
- It runs with limits on time, number of statements and memory, and with no access to files, the network or Windows.
- console.log lines are kept as the step's log.
- Because it touches nothing on the PC, it still runs in a dry run, so later steps get its result.
Routines that use it
Reshape an API reply
HTTP request fetches JSON, and Run JavaScript picks out and renames the fields that Write JSON value saves.
Work out a deadline
Calculate the next working day from today's date and pass it to Type text.
Summarise a list
List files returns a folder's files and Run JavaScript adds up their sizes for a Show banner message.
Settings
| Setting | What it does |
|---|---|
| Code | The code, as the body of a function: return the result. Read the routine's values from vars, steps, trigger and inputs (read-only). |
| Timeout | The code is stopped after this long. |
| Max statementsadvanced | The most statements the code may run (stops endless loops early). |
| Memory mb | The most memory the code may allocate. |
Good to know
- No access to files, the network or other programs; use the matching steps for those.
- Script steps must be turned on under Settings ▸ Advanced ▸ Allow script steps.
Questions
- Can the JavaScript step read my files or browse the web?
- No. It runs in a sandbox with nothing from Windows handed in. Use steps like Read text file or HTTP request and pass their results to the code.
- How does the code get values from the routine?
- It reads them from objects such as vars, steps, trigger and inputs. They are frozen copies, so the code can't change the routine's own values.