n8n If & Switch: A Practical Guide to Smarter, Growth-Focused Automation
From manual decisions to automated clarity
Every growing business eventually hits the same wall: too many tiny decisions, not enough time. You start with simple workflows, then suddenly you are juggling edge cases, exceptions, and “if this, then that” rules scattered across tools and spreadsheets. It gets noisy, and that noise steals focus from the work that really moves you forward.
This is exactly where conditional logic in n8n becomes a turning point. With the If and Switch nodes, you can teach your workflows to make decisions for you. They quietly handle routing, filtering, and branching so you can spend your energy on strategy, creativity, and growth.
In this guide, you will walk through a real n8n workflow template that reads customer records from a datastore and routes them based on country and name. Along the way, you will see how a few well-placed conditions can turn a basic flow into a powerful, reliable automation system.
Adopting an automation mindset
Before diving into the nodes, it helps to shift how you think about automation. Instead of asking “How do I get this one task done?” try asking:
- “How can I teach my workflow to decide like I do?”
- “Where am I repeating the same judgment calls again and again?”
- “Which decisions could a clear rule handle, so my team does not have to?”
The n8n If and Switch nodes are your tools for encoding that judgment. They let you build logic visually, without code, so you can:
- Filter out noise and focus only on what matters
- Handle different customer types or regions with confidence
- Keep workflows readable and maintainable as they grow
Think of this template as a starting point. Once you understand how it works, you can extend it, adapt it to your data, and gradually automate more of the decisions that currently slow you down.
When to use If vs Switch in n8n
Both nodes help you route data, but they shine in different situations:
If node: simple decisions and combined conditions
Use the If node when you want a clear yes/no answer. It is perfect when:
- You have a single condition, such as “Is this customer in the US?”
- You need to combine a few checks with AND / OR logic, for example:
- Country is empty OR
- Name contains “Max”
The If node returns two paths: true and false. That simple split is often enough to clean up your flow and make it easier to follow.
Switch node: many outcomes, one clear router
Use the Switch node when you need to handle three or more distinct outcomes. Instead of chaining multiple If nodes, a Switch node lets you define clear rules and send each item to the right branch, such as routing customers by country.
Together, If and Switch let you express complex business logic in a way that stays understandable and scalable, even as your automation grows.
Meet the example workflow template
The n8n template you will use in this guide is built around a simple but powerful scenario: reading customer data and routing records based on country and name. It is small enough to understand quickly, yet realistic enough to reuse in your own projects.
The workflow includes:
- Manual Trigger – start the flow manually for testing and experimentation
- Customer Datastore – fetches customer records using the
getAllPeopleoperation - If nodes – handle single-condition checks and combined AND / OR logic
- Switch node – routes customers into multiple branches by country, with a fallback
Within this single template, you will see three essential patterns that apply to almost any automation:
- A single-condition If to filter by country
- An If with AND / OR to combine multiple checks
- A Switch node to create multiple branches with a safe fallback
Once you grasp these patterns, you can start recognizing similar opportunities in your own workflows and automate them with confidence.
Step 1: Build the foundation of the workflow
Let us start by creating the basic structure. This foundation is where you will plug in your conditions and routing rules.
- Add a Manual Trigger node. Use this to run the workflow on demand while you are experimenting and refining your logic.
- Add your Customer Datastore node. Set the operation to
getAllPeopleso the node retrieves all customer records you want to route. - Connect the Datastore to your logic nodes. In n8n you can connect a single node to multiple downstream nodes. Connect the datastore output to:
- The If node for the single-condition example
- The If node for combined AND / OR logic
- The Switch node for multi-branch routing
- Prepare to use expressions. You will reference fields like
countryandnameusing expressions such as:={{$json["country"]}}={{$json["name"]}}
- Run and inspect. Click Execute Workflow as you go and inspect the input and output of each node. This habit helps you trust your automations and refine them faster.
With this structure in place, you are ready to add the decision-making logic that will turn this workflow into a smart router for your customer data.
Step 2: Single-condition If – filtering by country
Imagine you want to treat US-based customers differently, for example to send them region-specific notifications or apply US-only business rules. A single If node can handle that routing for you, reliably and automatically.
Configuration for a simple country filter
Set up your If node like this:
- Condition type: string
- Value 1:
={{$json["country"]}} - Value 2:
US
With this configuration the If node checks whether $json["country"] equals US.
- If the condition is true, the item goes to the true output.
- All other items flow to the false output.
How this small step creates leverage
This simple split unlocks a lot of possibilities:
- Send US customers into a dedicated notification or marketing sequence
- Apply region-specific logic, taxes, or compliance steps only where needed
- Route customers into different tools or services based on their country
One clear condition, one If node, and you have turned a manual decision into an automated rule that runs every time, without you.
Step 3: If with AND / OR – combining multiple checks
Real-world data is rarely perfect. You might have missing fields, special cases, or customers who need extra attention. That is where combining conditions in an If node becomes powerful.
In this template you will see an example that handles records where either the country is empty or the name contains “Max”. This could represent incomplete data, test accounts, or VIPs that require special handling.
Key settings for combined conditions
Configure your If node with multiple string conditions, for example:
{{$json["country"]}} isEmpty{{$json["name"]}} contains "Max"
Then use the Combine field to decide how these conditions interact:
- Combine operation:
ANYfor OR logic - Combine operation:
ALLfor AND logic
In this template, the configuration uses combineOperation: "any". That means the If node returns true when either condition matches.
- If the country is empty, the item matches.
- If the name contains “Max”, the item matches.
- If both are true, it also matches.
Practical ways to use combined conditions
Once you understand combined conditions, you can start using them to clean data and treat important records differently:
- Data validation Route records with missing country values to a cleaning or enrichment step, such as a manual review queue or an external API.
- Special handling Flag customers whose name matches certain keywords, such as VIPs, test accounts, or internal users, and route them into dedicated flows.
This is how you gradually build smarter automations: by capturing the small rules you already follow in your head and turning them into reusable, visible logic in n8n.
Step 4: Switch node – routing to multiple branches by country
As your automation grows, you will often have more than two possible outcomes. Maybe you want different flows for the US, Colombia, and the UK, with a safety net for all other countries. A Switch node makes this kind of branching clean and easy to understand.
Example Switch configuration
Configure your Switch node as follows:
- Value to check:
={{$json["country"]}} - Data type:
string - Rules & outputs:
- Rule 0:
US(routes to output 0) - Rule 1:
CO(routes to output 1) - Rule 2:
UK(routes to output 2)
- Rule 0:
- Fallback output:
3– catches all records that do not match a rule
Why the fallback output matters
The fallback output is your safety net. It ensures that any unexpected or new country values are still processed. Without it, data could silently disappear from your workflow.
Use the fallback branch to:
- Log unknown or new country values for review
- Send these records into a manual validation queue
- Apply a default, generic flow when no specific rule exists yet
This approach gives you confidence that your automation will behave predictably, even as your data changes or your customer base expands into new regions.
Best practices to keep your automations scalable
As you build more If and Switch logic into your workflows, a few habits will help you stay organized and avoid confusion:
- Use Switch for clarity when you have 3+ outcomes. A single Switch node is almost always easier to read than a chain of nested If nodes.
- Always include a fallback route in Switch nodes. This protects you from silent data loss and makes your workflow more resilient.
- Standardize your data before comparing. If you are unsure about capitalization, use expressions like
={{$json["country"]?.toUpperCase()}}to normalize values before checking them. - Document your logic on the canvas. Use sticky notes or comments in n8n to explain why certain conditions exist. This makes onboarding collaborators faster and helps your future self remember the reasoning.
- Use Code nodes for very complex logic. When you have many conditions or intricate rules, consider a Code node, but keep straightforward boolean checks in If nodes to maintain visual clarity.
These small practices compound over time, turning your n8n instance into a clear, maintainable system instead of a tangle of ad hoc rules.
Troubleshooting your conditions with confidence
Even with a strong setup, conditions may not always behave as expected. When that happens, treat it as an opportunity to deepen your understanding of your data and your automation.
If your conditions are not matching, try this checklist:
- Inspect Input and Output data. While executing the workflow, open each node and look at the actual JSON values under Input and Output. This often reveals small mistakes immediately.
- Check for spaces and case sensitivity. Leading or trailing spaces and inconsistent capitalization can cause mismatches. Use helpers like
trim()ortoUpperCase()in your expressions when needed. - Verify operators. Make sure you are using:
isEmptyfor missing fieldscontainsfor partial matches- Equality operators for exact matches
With a little practice, debugging conditions becomes straightforward, and each fix makes your automation more robust.
Real-world ways to apply If and Switch logic
The patterns in this template show up in many real automation scenarios. Here are a few examples you can adapt directly:
- Region-based notifications Send country-specific promotions, legal updates, or compliance messages by routing customers based on their country code.
- Data cleanup flows Detect incomplete or suspicious records and route them to manual review, enrichment APIs, or dedicated cleanup pipelines.
- Feature toggles and test routing Use name or email patterns to enable or disable parts of a flow for specific users, internal testers, or beta groups.
As you explore this template, keep an eye out for similar patterns in your own processes. Anywhere you are making repeated decisions by hand is a strong candidate for an If or Switch node.
Your next step: experiment, extend, and grow
The If and Switch nodes are not just technical tools. They are building blocks for a more focused, less reactive way of working. Each condition you automate is one less decision you have to make manually, one more piece of mental space you get back.
Use this template as a safe playground:
- Open n8n and import the example workflow.
- Run it with your own sample customer data.
- Adjust the conditions for your real-world rules, such as different countries, name patterns, or validation checks.
- Add new branches, new rules, and see how far you can take it.
Start simple, then iterate. Over time, you will build a library of automations that quietly support your business or personal projects, so you can focus on the work that truly matters.
Call to action: turn this template into your own automation engine
If you are ready to move from theory to practice, now is the moment. Open n8n, load this workflow, and begin shaping it around your data and your goals. Treat it as a starting point for a more automated, more intentional way of working.
If you would like a downloadable starter template or guidance on adapting these rules to your dataset, reach out to our team or leave a comment. We are here to help you refine your logic, improve your flows, and build automations you can rely on.
