Switch
The Switch node enables the flow to proceed from the output ports for which the provided JavaScript expressions evaluate to true.

If you assign a value of true to the bottom Output port, it can serve as a default when none of the preceding evaluations return true. However, remember to enable the Break option. If it's left unchecked, the flow will proceed from all ports that are evaluated as true.
How It Works
- The node receives a message and evaluates each configured output port condition in order
- For each condition:
- If the condition is empty, it evaluates to
false - If non-empty, the JavaScript expression is evaluated with access to
msg,global.get(), andflow.get() - The expression must return a boolean value (
trueorfalse)
- If the condition is empty, it evaluates to
- If Break is enabled:
- The node stops evaluating conditions after the first
trueresult - All remaining conditions are set to
false - Only one output port will send the message
- The node stops evaluating conditions after the first
- If Break is disabled:
- All conditions are evaluated regardless of previous results
- The message is sent to all output ports where the condition evaluates to
true
- If no conditions evaluate to
true, an error is raised - The message passes through unchanged to the selected output port(s)
Requirements
- At least one output port condition must be configured
- All conditions must be valid JavaScript expressions
- Expressions must evaluate to boolean values (
trueorfalse) - At least one condition must evaluate to
true, or an error will occur - Global/Flow variables accessed in conditions must exist
Error Handling
| Error Code | Description | Cause |
|---|---|---|
Core.Programming.Switch.ErrOnCreate | Config parse error | Invalid node configuration during creation |
Core.Triggers.Inject.OnMessage | Message parse error | Invalid message format received |
Core.Programming.Switch.NoCondition | No conditions configured | The Output Ports array is empty |
Core.Programming.Switch.InvalidCondition | Invalid condition | Condition expression cannot be evaluated or variable not found |
Core.Programming.Switch.EmptyCondition | Empty condition at position N | The Nth condition field is blank |
Programming.Switch.Eval | JavaScript evaluation error | Syntax error in one of the condition expressions |
Programming.Switch.Eval.Value | Value retrieval error | Cannot retrieve evaluated results |
Programming.Switch.Eval.Array | Array export error | Cannot convert evaluation results to array |
Programming.Switch.ErrExpr | Non-boolean expression | Condition expression returned a non-boolean value |
Core.Programming.Switch.ErrConditions | No matching condition | All conditions evaluated to false |
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if the Catch node is used.
Options
-
Break: Allows the flow to exit the loop or switch prematurely when any output port's evaluation returns true. If this option is not selected, the flow can proceed from multiple outputs that evaluate to true.
-
Output Ports: This option requires an array of expressions, one for each output port. Input a JavaScript expression corresponding to each port. The provided expression will be evaluated using the input value.
JavaScript Expression API
Within your condition expressions, you have access to:
msg- The current message object (e.g.,msg.status === "active")global.get(variableName)- Retrieve a global variable valueflow.get(variableName)- Retrieve a flow variable value- Standard JavaScript operators and functions
Usage Examples
Example 1: Route by Order Status
Configure Switch with 3 outputs:
- Output 1: msg.status === "pending"
- Output 2: msg.status === "completed"
- Output 3: true (default/else)
Break: enabled
Flow:
Get Order
└─ Switch
├─ [Port 1] Process Pending Order
├─ [Port 2] Archive Completed Order
└─ [Port 3] Handle Unknown Status
Route orders to different processing paths based on their status.
Example 2: Multiple Condition Routing (No Break)
Configure Switch with 3 outputs:
- Output 1: msg.amount > 1000
- Output 2: msg.priority === "urgent"
- Output 3: msg.customer.vip === true
Break: disabled
Flow:
Process Order
└─ Switch
├─ [Port 1] Send to Manager Approval
├─ [Port 2] Add to Urgent Queue
└─ [Port 3] Notify VIP Team
An order can trigger multiple outputs simultaneously (e.g., high-value urgent VIP order triggers all three).
Example 3: Numeric Range Routing
Configure Switch with 4 outputs:
- Output 1: msg.score >= 90
- Output 2: msg.score >= 70 && msg.score < 90
- Output 3: msg.score >= 50 && msg.score < 70
- Output 4: msg.score < 50
Break: enabled
Flow:
Calculate Score
└─ Switch
├─ [Port 1] Excellent - Send Reward
├─ [Port 2] Good - Send Encouragement
├─ [Port 3] Average - Send Tips
└─ [Port 4] Poor - Send Training Materials
Route based on numeric ranges with Break enabled to ensure only one path is taken.
Usage Notes
- Conditions are evaluated in order from top to bottom (Output 1, then Output 2, etc.)
- With Break enabled, only the first matching condition triggers - ideal for if/else-if/else logic
- Without Break, multiple outputs can fire - useful for triggering multiple parallel actions
- Use
trueas the last condition for a default/"else" case (works best with Break enabled) - The message object can be modified within expressions, but changes won't persist
- Empty/undefined fields in
msgevaluate to falsy values in JavaScript - Non-boolean expressions (returning strings, numbers, objects) will cause errors
Tips
- Use Break mode for mutually exclusive routing (status checks, priority levels)
- Disable Break when one input should trigger multiple parallel processes
- Place most specific conditions first, generic conditions last
- Use the last output port with condition
trueas a catch-all/default route - Test complex expressions in a Function node first before using in Switch
- Access nested object properties safely:
msg.user && msg.user.role === "admin" - Combine conditions with logical operators:
msg.age 1 or greater8 && msg.verified === true - Use global/flow variables for dynamic routing:
msg.priority === flow.get("currentPriority")