Skip to main content
Create your own
Lesson illustration

Conditional Workflow with If Nodes

Hello! Let's continue our journey into n8n.

In our last lesson, we mastered the Set node, learning how to transform, clean, and shape data as it flows through our workflow. This gave us precise control over the structure of our data.

Today, we'll build on that by learning how to control the flow of our workflow itself. We'll explore how to make decisions based on the data we're processing. This lesson focuses on using the If node to create conditional branches, which is the cornerstone of building intelligent and responsive automations.

As a developer, you're deeply familiar with if-else statements, which are fundamental to programming logic. The If node is n8n's visual equivalent, allowing you to direct items down a true path or a false path based on the conditions you define.

1. The Concept of Conditional Branching

In a simple workflow, every item follows the same single path from start to finish. However, most real-world scenarios require different actions for different situations. For example:

  • If a bug report is "urgent," notify a developer on Slack. Otherwise, just add it to a Jira board.
  • If a customer's order total is over $500, add a "VIP" tag.
  • If an email contains an invoice, extract the attachment. Otherwise, archive it.

This is where conditional branching comes in. The If node evaluates each item against a set of rules and sends it down one of two paths: true or false.

Single-branch vs. Multi-branch Workflow Logic
This diagram perfectly illustrates the power of branching. The simple workflow on the left processes every bug report the same way. The complex workflow on the right uses an **If node** to check for urgency, creating a separate, high-priority path for critical issues.

2. Building Your First Conditional Branch

Let's dive into how to configure the If node. The core process involves selecting a piece of data, choosing a comparison method (the "operator"), and providing a value to test against.

The following video provides an excellent step-by-step guide using a practical example of segmenting a customer list by age.

How to Use Conditional Logic in n8n (If Node Explained)

Watch this first segment of 'How to Use Conditional Logic in n8n' from the Tommy Eberle channel. It covers the essential setup of an If node, from selecting a value to seeing how the data is split.

Watch from the beginning until timestamp 03:10. Pay close attention to: How to drag a data field into the 'Value 1' box. The selection of data type ('Number') and operator ('is greater than'). How the output is split into 'true' and 'false' branches. The discussion of edge cases, like the difference between 'greater than' and 'greater than or equal to'.

As you saw, the basic steps are:

  1. Add an If node to your canvas.
  2. In the parameters panel, drag the data point you want to check (e.g., age from the input) into the Value 1 field.
  3. Ensure the Type is correct (n8n usually makes a good suggestion). The available operators will change based on the type.
  4. Select an Operation (e.g., is Greater Than).
  5. Enter the value to compare against in Value 2 (e.g., 40).

After executing the node, you'll see two outputs. You can then connect other nodes to the true and false paths to build out your distinct logic branches.

The official n8n documentation also provides a very straightforward example in its "Your First Workflow" tutorial, which you can review in the resource LINK. It shows how to use the Contains operator for a string comparison.

3. Handling Different Data Types and Comparisons

The real power—and potential complexity—of the If node lies in how it handles different types of data. A comparison that works for a number won't work for a string or a date. Your software development background gives you a head start here, as the concepts of type safety and casting are directly applicable.

String Comparisons

When dealing with text, you often need more flexibility than a simple "equals" check. Is the comparison case-sensitive? Do you just need to see if a word exists within a larger block of text?

Data Type Mismatches

What happens if you try to compare a date to a number? Or a string that looks like a number ("40") with an actual number (40)? n8n has settings to manage this, but it's important to be deliberate.

Let's return to the video, which covers these nuances very well.

How to Use Conditional Logic in n8n (If Node Explained)

These next two clips from the same video are crucial for building robust workflows. They cover how to handle string-specific options and what to do when your data types don't match.

First, watch the section on string comparisons from 09:12 to 11:39. Notice the 'Ignore case' option and the use of the 'contains' operator to handle messy data. Next, watch the section on data types and conversion from 06:11 to 09:12. This explains the 'Convert types where required' checkbox, which is n8n's version of implicit type casting. Pay attention to the warning about how this can sometimes hide bugs.

Key takeaways from this:

  • For Strings: Use the Ignore case option for case-insensitive matching. Operators like contains, startsWith, and regex provide powerful ways to validate text data.
  • For Types: Be mindful of data types. While Convert types where required can be convenient, it's often better to see an error and explicitly fix the data (perhaps with a Set node first) than to rely on an automatic conversion that might not behave as you expect.

4. Combining Multiple Conditions

A single check is often not enough. You might need to check if a user is an 'admin' and is 'active', or if a ticket is 'high priority' or submitted by a 'VIP customer'. The If node allows you to combine multiple conditions using AND and OR logic.

  • AND: All conditions must be met for the result to be true.
  • OR: At least one condition must be met for the result to be true.

This is directly analogous to using && and || operators in your code.

How to Use Conditional Logic in n8n (If Node Explained)

Let's see how to add multiple conditions in the If node's interface.

Watch the segment from 03:32 to 06:11. The example combines an age check (number) and a 'last contacted' check (date/time) to illustrate how AND vs. OR dramatically changes the outcome.

By clicking "Add Condition," you can build up complex rules to precisely filter and route your data. The article "Using IF nodes for conditional logic" (LINK) also provides a good textual reference for these concepts in its "Combining Multiple Conditions" section.

Test your understanding!

A webhook receives the following JSON payload for a new user signup:

{
  "email": "test.user@example.com",
  "plan": "premium",
  "login_count": 0,
  "is_verified": false
}

You need to route this user to a special onboarding flow only if they meet specific criteria. How would you configure an If node to be true only for users who are on the 'premium' OR 'enterprise' plan, AND their email address is verified?

Show answer

You would configure the If node with a combination of OR and AND logic, which n8n handles by grouping conditions.

  1. Set the overall combination logic to AND.
  2. Condition 1 (Grouped OR):
    • Click "Add Condition" and select OR for the combination within this group.
    • Sub-condition 1.1: Value 1: {{$json.plan}}, Operation: equals, Value 2: premium.
    • Sub-condition 1.2: Value 1: {{$json.plan}}, Operation: equals, Value 2: enterprise.
  3. Condition 2 (AND):
    • Value 1: {{$json.is_verified}} (Type: Boolean)
    • Operation: is True

This setup ensures that the entire condition is true only if the is_verified flag is true AND the plan is one of the specified values.

n8n Workflow: Invoice Payment Automation with Conditional Logic
This real-world example shows If nodes in action. The workflow checks if an invoice has a PO number and later if a corresponding deal was found, branching the logic to send different Slack messages and perform different updates.

Conclusion

You've now learned how to add decision-making to your workflows. The If node is a fundamental building block that transforms your automations from simple data-passers into intelligent processes.

Key Takeaways:

  • The If node splits workflow execution into two paths: true and false.
  • Conditions are built by comparing an input value (Value 1) to a static or dynamic value (Value 2) using an operator.
  • Always be mindful of data types (Number, String, Boolean, etc.) and use options like Ignore case for strings where appropriate.
  • Combine rules using AND and OR to create sophisticated, multi-part logic.

The If node is perfect for binary, yes/no decisions. But what happens when you have multiple possible outcomes? For example, what if you need to route a support ticket based on four different priority levels: Low, Medium, High, and Critical? You could chain multiple If nodes together, but that quickly becomes messy.

In our next lesson, we will address this exact scenario by learning how to use the Switch node for multi-path routing, which provides a much cleaner way to handle decisions with more than two outcomes.

Can't find a good explanation? Sign up and we'll make it for you

Sign up