Blocks & Flow EditorCommon

execute javascript

Run custom JavaScript to transform messages and implement custom logic

The execute javascript block runs custom JavaScript code when a message arrives. Use it to transform data, compute values, or implement logic not available in other blocks.

Bot Studio execute javascript block on canvas Execute javascript block editor with On Message, Setup, and Modules tabs

Configuration

FieldDescription
NameOptional display label on the canvas.
OutputsNumber of output ports (default 1). Use multiple outputs to send messages to different branches.
On MessageJavaScript code executed when a message arrives. Receives msg, node, context, and flow. Return msg to pass it on, or call node.send() for multiple outputs.
On StartCode run once when the flow is deployed or started. Use for one-time initialization.
On StopCode run when the flow is stopped or re-deployed. Use for cleanup.
ModulesOptional external modules to import. Specify module name and the variable name to import as.

On Message code context

VariableDescription
msgThe incoming message object (msg.payload, custom properties, etc.)
nodeReference to this block — use node.send(msg) or node.error()
contextFlow and global context — context.get() / context.set()
flowShorthand for flow-scoped context

Outputs

PortDescription
Output 1 (default)Sends the returned msg object to the next block
Additional outputsAvailable when Outputs is set greater than 1 — use node.send([msg1, msg2])

Notes

  • msg.payload is commonly overwritten by downstream blocks — store persistent values on custom msg properties
  • Syntax errors are reported in the debug sidebar and block status
  • Test JavaScript logic with print blocks before deploying to production agents
  • External module loading may be restricted depending on agent configuration