节点 / builtin / flow
Switch
Route items to any number of named branches, with a fallback for the rest
此内容尚不支持你的语言。
Send each item down one of several named branches, with a fallback branch for the rest.
Try it
Section titled “Try it”Classify and Route:包含 8 个步骤的工作流,从 Run now 开始,到 Other branch 结束,含 1 个分支点。
- Billing branch(Display Markdown — 打开其文档页面) 如果 Billing
- Technical branch(Display Markdown — 打开其文档页面) 如果 Technical
What it does
Section titled “What it does”Switch has one output per rule you add, named after the rule, plus a fallback output for items that match no rule. IF gives you two branches; Switch gives you as many as you need, without nesting IF nodes.
There are two ways to pick the branch, set with Mode:
- Rules: each rule has its own Conditions, built like the ones in IF. Rules are tried from top to bottom, and by default the first one that matches wins, so put narrow rules above broad ones. A rule with no conditions never matches.
- Expression: one value, Value To Match, is compared with each rule’s Output Name. The item goes to the branch whose name is exactly that value. The comparison is done as text, so the number
200matches a branch named200.
Items that match nothing go to the fallback branch (Anything else by default). Turn off Add A Fallback Branch and they are dropped instead. Set On Multiple Matches to Every match to send an item to every branch it matches.
When to use it
Section titled “When to use it”- Route items to Billing, Bug or Other depending on words in their title (Rules mode).
- Split a list by a status or category field whose values are the branch names (Expression mode).
- Handle three or more cases where you would otherwise chain IF nodes.
For two branches, IF is simpler. To drop non-matching items, use Filter.
Inputs and settings
Section titled “Inputs and settings”| 设置项 | 类型 | 作用 |
|---|---|---|
| Mode | Choice | Decide the branch by conditions, or by matching a value to a name. Options: Rules, Expression. 默认值:Rules |
| Rules | List of entries | One per branch, tried from top to bottom. |
| Rules (each entry) › Output Name (必填) | Text | Name of the branch items matching this rule are sent to. |
| Rules (each entry) › Conditions | Conditions | When these hold, the item takes this branch. |
| Value To Match | Value | Compared against each output name, in Expression mode. |
| On Multiple Matches | Choice | Whether an item takes only the first matching branch, or every one. Options: First match only, Every match. 默认值:First match only |
| Add A Fallback Branch | Toggle | Send items matching no rule to an output of their own. 默认值:On |
| Fallback Name | Text | Name of the branch for items matching no rule. 默认值:Anything else |
- In Expression mode, rules only need an Output Name; their conditions are ignored. Set Value To Match to the field to compare, for example
{{ $input.status }}, and name the rules after the possible values (open,closed). Matching is case-sensitive. - A rule left without a name is called
Rule 1,Rule 2, and so on. Two rules with the same name get a suffix, such asUrgent (2).
Outputs
Section titled “Outputs”-
Anything else
More ports appear as you add them in the settings (one per rule).
Items leave unchanged through the branch they took. Connections are tied to the branch name: reordering rules keeps every connection in place, but renaming a rule removes the connection that left it, and the canvas tells you so.
Dependencies and credentials
Section titled “Dependencies and credentials”None. This node needs no connection and has no slots for other nodes.
Example workflow
Section titled “Example workflow”Handle support tickets by status:
- Http Request gets
https://api.example.com/tickets, which returns a list of tickets. - Split Out with Field To Split Out
dataand Output field nameticketmakes one item per ticket. - Switch with Mode Expression, Value To Match
{{ $input.ticket.status }}, and two rules namedurgentandopen. Keep the fallback namedAnything else. - From urgent: Slack posts
{{ $input.ticket.title }}to your support channel. From open: Todoist creates a task. Leave Anything else unconnected to ignore the rest.
Common issues
Section titled “Common issues”- “Switch needs at least one rule. Add one, and name the branch it routes to.” Add a rule under Rules.
- “No source node is connected to this node.” Connect a node to the Switch input.
- Everything goes to the fallback. In Rules mode, a rule without conditions never matches, so check each rule has its conditions. In Expression mode, the value must equal an Output Name exactly, including capital letters and spaces.
- A connection disappeared after editing a rule. You renamed the rule, which disconnects its branch. Reconnect it from the new name.
- An item went down only one branch although it matched two. On Multiple Matches is First match only. Switch it to Every match.
Related nodes
Section titled “Related nodes”- IF: two branches, true or false.
- Filter: keep only matching items.
- Funnel: bring the branches back together afterwards.
- Text Classifier: let an AI model pick the category first.