Get startedGet started for free

Conditional logic in workflows

1. Conditional logic in workflows

Hey, it's Frank again. In this video, we'll make our workflows think by adding Conditional Logic. By the end, we'll know when to use If and when to use Switch, how to design clean branches, and how to test them safely.

2. Why branching matters

The thing is that real processes don't run in a straight line. For example, an inquiry from a VIP enterprise user of our app shouldn't be handled like a casual inquiry from a low-tier member. Branching lets a single workflow choose different actions based on the data it sees.

3. If vs Switch (plain-English)

We've got two main ways to branch in n8n: the "If" node and the "Switch" node. The "If" node answers one question with two branches or paths; if the condition is met, or if the condition is not met. We may also stack multiple conditions with AND or OR statements. The Switch node compares one incoming field value against several paths and picks the matching one.

4. Rule of thumb

Here's a rule of thumb: if it's a yes/no question, use "If";

5. Rule of thumb

and if we're choosing one of many categories, use "Switch". If unsure, use Switch and add a default branch to catch anything unexpected.

6. Rule of thumb

And if nothing matches, add a Fallback Branch. This is a fallback option, like saying "otherwise, do this".

7. Example: Acme Support Desk

Let's say we're building a workflow for a simple order management system, and we want to handle orders differently depending on their details. We'll look at the fields and their values on each order- things like the quantity (is it a bulk order or a regular one) and the category (books, electronics, or other). Based on those values, we can decide how to process and where to route each order. This matters because bulk orders can be more profitable if handled efficiently, and routing by category ensures the right team processes each order quickly.

8. If node in action

To decide whether an order should be treated as bulk, we'll check the quantity field. If the quantity is greater than 14, we'll mark it as a bulk order for special handling; otherwise, it stays as a regular order. Prioritizing bulk orders ensures larger customers get the right attention, improving efficiency and satisfaction.

9. Switch node in action

Next, to determine which team should process the order, we'll check the category field. If it's "Books", it goes to the Books team. If it's "Electronics", it goes to the Electronics team. If it doesn't match either, it goes to the General team. Notice how this example wouldn't work well with just an If node, since there are multiple possible categories, the Switch node makes it much easier to handle.

10. Let's practice!

Let's test what we've learned by creating a workflow that combines If and Switch nodes and observing how they handle different ticket scenarios.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.