Skip to main content
Function nodes let you write JavaScript code for logic that expressions and decision tables can’t handle. Use them for complex algorithms, external API calls, or custom data transformations.

Creating a function node

  1. Drag a Function node onto your decision graph
  2. Connect it between other nodes
  3. Click Edit Function to open the code editor

Basic structure

Every function node exports a handler that receives input and returns output:
The input parameter contains data from the previous node in your graph.

Accessing previous nodes

Use input.$nodes to access outputs from any upstream node in your graph:
Use input.$nodes.NodeName.field to reference any field from an upstream node’s output. Node names are case-sensitive and must match exactly.

Example: Calculate loyalty points

Supported libraries

Function nodes include several built-in libraries:

Using dayjs

Using big.js for precision

Making HTTP requests

Async/await

Function nodes support async operations. Use async/await for any asynchronous logic:

Debugging

Use console.log to debug your functions. Output appears in the simulator:

Execution limits

Function nodes have these constraints: If your function exceeds the timeout, evaluation fails with an error.

Best practices

Keep functions focused — Each function should do one thing well. Use multiple function nodes for complex workflows. Handle errors gracefully — Wrap risky operations in try/catch blocks. Avoid side effects — Functions should be deterministic when possible. Same input should produce same output. Use expressions first — If the ZEN expression language can handle your logic, prefer it over function nodes for better performance.