KeyRoutines
StepProscript.javascript

Run small JavaScript calculations inside a routine

Run JavaScript runs a short piece of JavaScript in a locked-down sandbox and hands its result to later steps. It needs KeyRoutines Pro and is meant for calculations and reshaping data, not for controlling the PC.

KeyRoutines Pro is a one-time $29.99 upgrade for up to 2 PCs.

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

SettingWhat it does
CodeThe code, as the body of a function: return the result. Read the routine's values from vars, steps, trigger and inputs (read-only).
TimeoutThe code is stopped after this long.
Max statementsadvancedThe most statements the code may run (stops endless loops early).
Memory mbThe 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.

Pairs well with

Build this routine in KeyRoutines

Free from the Microsoft Store for Windows 11 and 10. Pro is a one-time upgrade.