Switch
Route messages to different branches based on message properties, sequence information, or a JSONata expression.
How it works
Switch rules are evaluated in order from top to bottom.
value rules test a specific message, flow, global, or environment value
sequence rules work with message sequences such as those produced by
SplitJSONata rules evaluate an expression against the whole message and match when the expression returns a true value
Otherwiseis the fallback rule when no earlier rule matches
In the current editor, new Switch nodes start with an Otherwise rule and the editor keeps it last. For most Contextual agent flows, enable the option to stop after the first match so one message follows one primary branch and Otherwise acts as the final fallback output.
Sending the same message down multiple matching branches is an advanced pattern. It can create race conditions if more than one branch can reach terminal behavior such as Event End, Event Error, or an HTTP response path.
Important rule behavior
is true,is false, andis nulluse strict comparisons and do not coerce values between typesis emptyandis not emptywork on strings, arrays, Buffers, and objects; they do not matchboolean,null, orundefinedvaluessequence rules apply to message sequences and can be used with data produced by
Split
Message sequences
By default, Switch does not change msg.parts when it receives a message that belongs to a sequence.
The recreate message sequences option can be enabled to create new sequences for each matching rule. In that mode, the node buffers the full incoming sequence before sending the new sequences onward.
Common uses
branch on HTTP status or response content
continue pagination only when a token or next-page value is present
separate success and error paths after a Function or Request node
route event types to different processing branches
Last updated
Was this helpful?