n8n: IF vs Switch for Conditional Logic, With the Real Expressions and Node JSON
说明与用途
在 n8n 中,使用 If 和 Switch 节点按预算和服务类型路由表单提交,并通过 fallback 输出防止数据丢失。
问题
Small businesses need to route form submissions based on budget and service type, but default n8n workflows process every item the same way, causing manual filtering or missed emergencies.
结果
The workflow now routes high‑budget and emergency requests directly to the owner, logs other requests, and prevents silent loss of data by using a Switch fallback.
工作流
- Add an If node to test if $json.Budget > 1000 and route true to Gmail, false to Google Sheets.
- Use a Switch node before the If to route Service values: Repair → Gmail, Emergency → Gmail, others → fallback.
- Configure the Switch fallback output to ensure unmatched items (e.g., Installation) are not lost.
- Use expressions like {{ Number($json.Budget) }} when budget is sent as text.
- Stack multiple conditions in the If node with AND/OR as needed.
证据
The If node asks one question and has two exits, true and false. Every item takes one or the other, never both.
An item that matches none of your Switch rules is ignored by default. No error, no warning. It just stops.
If your form sends the budget as text, convert it in the expression instead of switching the comparison to String: {{ Number($json.Budget) }}.
- 记录日期: 2026-10-24T20:41:06.739Z