Code Node
The Code Node lets you write and execute custom JavaScript or Python code within your workflow. Use it when JSONata expressions in Mapping Nodes aren’t sufficient for your logic requirements.The Code Node provides full programming flexibility. Use it for complex calculations, custom validations, data transformations that exceed JSONata capabilities, or integrating custom business logic.
Overview
Use a Code Node when you need to:- Perform complex calculations or algorithms
- Implement custom validation logic
- Work with dates and times in sophisticated ways
- Loop through arrays with complex transformations
- Call utility functions or libraries
- Handle edge cases that JSONata can’t express
When to Use Code Node vs. Other Nodes
Configuration
Click on a Code Node to open its configuration panel.Basic Settings
Language Options
- JavaScript
- Python
- Familiar syntax for web developers
- Access to standard JavaScript built-ins
- ES6+ features supported
Accessing Context
Your code receives the workflow context and must return the updated context.JavaScript
Python
Insurance Examples
Calculate Days Since Loss
Determine how many days have passed since the incident and flag urgent claims.- JavaScript
- Python
Validate Policy Number Format
Check if a policy number matches expected patterns and extract components.- JavaScript
- Python
Calculate Claim Reserve Estimate
Estimate initial reserve based on claim type and details.- JavaScript
- Python
Parse and Normalize Address
Clean up and standardize address components.- JavaScript
- Python
Process Multiple Line Items
Loop through an array of claim items and calculate totals.- JavaScript
- Python
Error Handling
Try-Catch Pattern
Wrap your code in try-catch to handle errors gracefully.- JavaScript
- Python
Branching After Code Node
Use the error flag in subsequent Decision Table or Mapping nodes:Best Practices
Keep Code Focused
Each Code Node should do one thing well:Use Descriptive Variable Names
Always Spread Context
Never return just your new fields:Handle Null/Undefined Values
Add Comments for Complex Logic
Test Edge Cases
Before deploying, test with:- Empty strings and null values
- Empty arrays
- Missing nested properties
- Unexpected data types
- Boundary values (zero, negative numbers)
Common Issues
TypeError: Cannot Read Property of Undefined
Symptom: Code fails when accessing nested properties. Fix: Use optional chaining or defensive checks:Context Lost After Code Node
Symptom: System properties liketenantId are missing.
Fix: Always spread the original context:
Infinite Loop
Symptom: Workflow times out in Code Node. Fix: Add loop limits:Floating Point Precision
Symptom: Money calculations have weird decimals (e.g.,10.000000001).
Fix: Round final values:
Next Steps
Mapping Node
Use JSONata for simpler transformations
Decision Table Node
Route based on code output
Task Node
Send processed data to external systems
Workflow Examples
See Code Node in complete workflows

