Skip to content
Docs

Switch

Switch routes the run down one of several branches. You define an ordered list of cases, each with a condition and a target branch; cases are evaluated top to bottom, the first case whose condition is truthy wins, and every other branch is skipped. You find it on the node picker’s Control flow shelf.

The Switch node's settings form, with the fields described below
The Switch node's settings form, with the fields described below
FieldTypeDefaultDescription
Cases (cases)list (required) — The ordered list of branches to evaluate — each case has a condition and the branch to take when it is the first to match.
Label (cases[].label)string (required) —
Condition (cases[].condition)boolean ✦ (required) —
Target node (cases[].targetNodeId)string (required) —
Default target node (defaultTargetNodeId)string (optional) — The branch to take when no case matches — leave empty to end the run at the Switch instead.

Fields marked ✦ accept expressions.

Each case has a label (recorded in the output when the case matches), a condition, and a target: the first node of that case’s branch. Connect one edge from the Switch’s output handle to each branch’s first node, then pick that node as the case’s target. The condition is a bare boolean expression without {{ }} echo tags, exactly as on Conditional Exit: false, null, 0, "", and empty arrays are falsy, everything else is truthy, and an empty expression counts as falsy. See How-to: Use expressions for the full syntax.

  1. The Switch evaluates each case’s condition in order and stops at the first truthy one.
  2. When no case matches, it takes the default branch, or ends the run at the Switch when no default is set.
  3. Only the chosen branch runs. Nodes on unchosen branches are skipped entirely, but a node where branches merge back together still runs.

The decision is made once and recorded, so a retried or replayed run follows the same branch rather than re-evaluating the conditions.

The node emits a JSON envelope describing the decision:

{ "chosen": "<node id of the chosen branch's first node>", "matchedLabel": "high-priority" }

matchedLabel is the matching case’s label, "default" when the default branch was taken, or null when nothing matched.

A run report for Route shipments by weight: the By weight Switch outputs chosen and matchedLabel Over a tonne, and only Book a truck, the branch it chose, runs after it
A run report for Route shipments by weight: the By weight Switch outputs chosen and matchedLabel Over a tonne, and only Book a truck, the branch it chose, runs after it

Route incoming tickets by priority. The Switch has three outgoing edges, one to each branch’s first node:

Label Condition Target
urgent $start->priority === 'urgent' first node of the escalation branch
high $start->priority === 'high' first node of the priority queue branch

Set the default branch to the normal-handling branch’s first node. A ticket started with {"priority": "urgent"} takes the escalation branch; anything without a matching priority takes the default branch.

  • The chosen branch’s first node receives the decision envelope as $prev, not the data that flowed into the Switch. On the first node of each branch, read upstream data explicitly, for example via $workflow->node('Fetch order') or $start.
  • Case targets are plain node choices, not expressions: the routing decision must map to a concrete node in the flow’s graph.