How Branching works in n8n Workflows | Smart Automations with Multiple Paths

Learn how branching works in n8n workflows using the Switch node to automate multi-path business processes like order status management.

Table of Contents

All right! In this tutorial, you will learn how to implement branching logic in n8n workflows to automate complex business processes involving multiple decision paths. Using a practical example of order status management, you will discover how to fetch data from Google Sheets, apply branching with the Switch node, and send notifications via email and Slack — all without writing any code.

This lesson will deepen your understanding of n8n’s powerful branching capabilities to create smart automations that handle multiple scenarios efficiently. For more on how to access and manipulate data within nodes, check out our guide on Expressions in n8n.

Understanding the Business Scenario

Imagine a business where an operator manually reviews orders in various states: Pending, Processing, Canceled, and Refunded. Based on the order status, the operator performs different actions:

  • Pending orders: Alert the customer service team via email to follow up with the customer.
  • Processing orders: Notify the operations team via Slack for expedited shipping (especially for high-priority orders).
  • Canceled or refunded orders: Send an official email to the finance team and notify them via Slack, especially during financial cycles like month-end.

Manual handling of this workflow is time-consuming and error-prone, often taking hours daily. Automating this process in n8n can save time, reduce errors, and ensure timely notifications. Understanding how to link related data items can also enhance your workflow’s efficiency; see our lesson on n8n Item Linking Explained for more details.

Step 1: Create a New Workflow and Add a Trigger

  1. Log in to your n8n cloud instance or local workspace.
  2. Click Create Workflow to open a blank canvas.
  3. Add a trigger node to start the workflow. For testing purposes, use the Manual Trigger node.
  4. In a real-world scenario, replace this with a Schedule Trigger node to run the workflow automatically every day at a specific time (e.g., 9:00 AM).

Step 2: Fetch Order Data from Google Sheets

The order data is stored in a Google Sheet with columns like Order ID, First Name, Last Name, Customer Email, Order Status, and Order Date.

  1. Add a Google Sheets node.
  2. Configure the node:
    • Resource: Sheet
    • Operation: Get Rows
    • Authentication: Use your pre-configured Google Sheets credentials.
    • Document: Select your Google Sheets document containing the order data.
    • Sheet: Choose the specific sheet with the order records.
  3. Leave filters blank to fetch all rows.
  4. Click Execute Node or Test Step to fetch the data.
  5. Verify that the node outputs a list of JSON objects, each representing an order.

Viewing Data in JSON and Table Formats

  • Switch between JSON and Table views to inspect the data.
  • Each item in the list represents an order with properties like orderId, orderStatus, etc.

For more details on working with data in n8n, refer to the n8n Data Documentation{:target="_blank"}.

Step 3: Add a Switch Node for Branching Logic

Since you need to handle multiple order statuses differently, you’ll use the Switch node instead of multiple If nodes.

  1. Add a Switch node connected to the Google Sheets node.

  2. Configure the Switch node:

    • Property to Evaluate: Use an expression to get the order status property:

      {{$json["orderStatus"]}}
      
    • Rules:

      • Add a rule for each status:
        • pending
        • processing
        • canceled
        • refunded
      • For each rule, set the comparison to String Equals and enter the status value.
    • Enable Ignore Case to handle variations in letter casing.

    • Set Fallback Output to ignore items that don’t match any rule (e.g., shipped or delivered).

  3. Rename each output branch for clarity:

    • Output 1 → Pending Orders
    • Output 2 → Processing Orders
    • Output 3 → Canceled Orders
    • Output 4 → Refunded Orders
  4. Test the node to see how many items fall into each branch.

Using the Switch node simplifies managing multiple conditions with multiple outputs, avoiding complex nested If nodes. For more on this node, see the Switch Node Documentation{:target="_blank"}.

Step 4: Send Email Notifications for Pending Orders

You want to notify the customer service team about pending orders via email.

  1. Add an Amazon SES node (or a generic Send Email node if you prefer SMTP).

  2. Connect the Pending Orders output from the Switch node to this email node.

  3. Configure the email node:

    • Operation: Send

    • From Email: e.g., no-reply@yourdomain.com

    • To Email: Customer service team email (preferably a distribution list)

    • Subject: Use an expression to include order ID:

      Order {{$json["orderId"]}} is in Pending State
      
    • Body: Write a message explaining the pending status and any action required.

  4. Execute the node to test sending emails.

Step 5: Send Slack Notifications for Processing Orders

For processing orders, you want to notify the operations team on Slack.

  1. Add a Slack node.

  2. Connect the Processing Orders output from the Switch node to the Slack node.

  3. Configure the Slack node:

    • Resource: Message

    • Operation: Send

    • Authentication: Use your configured Slack OAuth token.

    • Channel: Select the channel used by the operations team (e.g., #high-priority-processing-orders).

    • Message Text: Compose a message with order details:

      Order {{$json["orderId"]}} is high priority but still in processing state. Please expedite!
      
  4. Test the node to ensure Slack messages are sent correctly.

Step 6: Notify Finance Team for Canceled and Refunded Orders

Both canceled and refunded orders require notifications via email and Slack.

Step 6.1: Set Up Email Notification

  1. Copy the email node used previously and connect it to both the Canceled Orders and Refunded Orders outputs from the Switch node.

  2. Adjust the email subject and body to reflect the canceled/refunded status:

    • Subject:

      Refunded/Canceled Order {{$json["orderId"]}} Notification
      
    • Body: Include relevant details for the finance team.

  3. Test the node to confirm emails are sent for these orders.

Step 6.2: Set Up Slack Notification

  1. Copy the Slack node and connect it to both Canceled Orders and Refunded Orders outputs.
  2. Configure the Slack channel to one used by the finance team (e.g., #canceled-refunded-orders).
  3. Compose a simple message indicating the order status and ID.
  4. Test the Slack node to verify messages appear in the correct channel.

If you need to transform or add additional data before sending notifications, consider using the Set Node in n8n to customize your data payloads.

Step 7: Organize and Test Your Workflow

  • Use the Tidy Up option in n8n to neatly arrange your nodes.
  • Run the entire workflow manually to verify that:
    • Orders are fetched correctly.
    • Branching routes orders to the right nodes.
    • Emails and Slack messages are sent as expected.

Understanding Branching in n8n

As demonstrated, n8n supports two types of branching:

  1. Exclusive branching: Each item follows one path based on conditions (e.g., the Switch node routing orders based on status).
  2. Parallel branching: An item can be sent to multiple paths simultaneously (e.g., canceled orders triggering both email and Slack notifications).

Using the Switch node simplifies managing multiple conditions with multiple outputs, avoiding complex nested If nodes.

Common Mistakes & Troubleshooting

  • Not renaming output branches: This leads to confusion when debugging. Always rename outputs in the Switch node for clarity.
  • Incorrect expression syntax: Use the expression editor to drag and drop properties instead of typing manually to avoid syntax errors.
  • Case sensitivity issues: Always enable Ignore Case in the Switch node to handle inconsistent data formats.
  • Slack or email credentials misconfigured: Ensure your Slack OAuth token and email SMTP/SES credentials are set up correctly before running tests.
  • Sending too many messages at once: Slack and email providers may rate-limit you. Consider batching or adding delays if processing large volumes.

Quick Reference Cheat Sheet

Step Node Type Key Settings
Trigger Manual / Schedule Trigger Set schedule or manual execution
Fetch Orders Google Sheets Operation: Get Rows, select sheet and document
Branch by Order Status Switch Property: {{$json["orderStatus"]}}, add rules for each status, enable Ignore Case
Notify Customer Service Amazon SES / Email To: Service team, Subject/body with order info
Notify Operations Team Slack Channel: Processing orders, Message with order ID
Notify Finance Team (Email and Slack) Email & Slack Channels and emails for finance, message with order ID

By following this tutorial, you can efficiently automate complex workflows with multiple decision paths in n8n, saving time and reducing manual errors. As shown in the video above, leveraging the Switch node for branching is a powerful method to handle diverse business scenarios seamlessly.

Frequently Asked Questions

Configure the Switch node to evaluate the order status property and define separate branches for each status like Pending, Processing, or Canceled.

Yes, after branching with the Switch node, add Email and Slack nodes in each branch to send targeted notifications based on specific conditions.

Use the Google Sheets node to get rows from your sheet, then connect it to the Switch node to evaluate data fields for branching logic.

You can use triggers like Manual Trigger for testing or Schedule Trigger to run the workflow automatically at set times.

The Switch node simplifies managing multiple conditions in one node, making workflows cleaner and easier to maintain compared to multiple If nodes.

Dheeraj Sharma

Dheeraj Sharma

AI Systems Builder
Creator of the n8n Zero to Hero course (42 lessons, 31+ hours). I help solopreneurs build AI systems that grow revenue without growing workload.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources