IOLEBA

 IOLEBA N8N Textbook – Table of Contents

IOLEBA
Chapter 5

Workflow Control and Logic

Introduction

You've mastered the fundamentals. Now we'll explore how to add intelligence to workflows through control structures and logic. Instead of simple linear flows, you'll create workflows that make decisions, handle multiple scenarios, loop through data, and manage errors gracefully.

The IF Node: Conditional Branching

The IF node evaluates conditions and routes data down different paths based on whether conditions are true or false.

Basic IF Node Structure

INPUT DATA
    ↓
[IF NODE: Check Condition]
    ↙          ↘
  TRUE        FALSE
    ↓            ↓
Action A    Action B

Condition Types

Type Use Case Example
Boolean True/false values Is customer active?
Number Numeric comparisons Order total > $100?
String Text comparisons Status = "pending"?
Date & Time Date comparisons Due date in past?

Multiple Conditions

AND: ALL conditions must be true
OR: ANY condition can be true

Example: Order total > $100 AND customer is VIP

Real-World Example: VIP Customer Check
  • Condition: Lifetime value > $5000 AND membership >= 3 years
  • True: Send to VIP support team
  • False: Send to standard support queue

The Switch Node: Multiple Path Routing

While IF handles binary decisions, Switch routes data to multiple paths based on various conditions.

Scenario Use
2 outcomes IF Node
3+ outcomes Switch Node
Example: Customer Tier Assignment
  • Output 0 (Platinum): Value >= $10,000
  • Output 1 (Gold): Value >= $5,000
  • Output 2 (Silver): Value >= $1,000
  • Output 3 (Bronze): All others

The Merge Node: Combining Data

When workflows split into branches, Merge nodes bring them back together.

Mode Behavior
Append Combines all items
Merge By Fields Matches by field
Wait Waits for all branches

Loops and Batch Processing

The Split In Batches node divides large datasets into manageable chunks.

Example: Bulk Email with Rate Limiting
  • Send 1,000 emails without hitting API limits
  • Batch Size: 50 emails
  • Wait Between Batches: 120 seconds
  • Result: 1,000 emails over ~40 minutes

Error Handling

Production workflows must handle errors gracefully.

Error Handling Best Practices:
  • Enable retries for network-dependent nodes
  • Use Continue On Fail for optional operations
  • Set up error workflows for critical processes
  • Log errors to external systems
  • Test error paths deliberately

Node-Level Error Settings

Setting Effect
Continue On Fail Workflow continues despite error
Retry On Fail Automatically retries operation
Max Retry Number of retry attempts

Wait Node: Timing and Delays

The Wait node pauses workflow execution for specified time or until conditions are met.

Example: Customer Nurture Campaign
  1. New customer signs up
  2. Send welcome email immediately
  3. Wait 3 days
  4. Send educational email #1
  5. Wait 3 days
  6. Send educational email #2

Building Complex Logic Flows

Pattern 1: Multi-Stage Decision Tree

Intelligent Lead Router:

  1. Webhook receives lead
  2. IF: Company size > 500? → Flag as "Enterprise"
  3. Switch: Route by industry (Tech/Healthcare/Finance)
  4. IF: Budget > $50,000? → Assign to senior rep
  5. Create lead in CRM
  6. Notify assigned rep

Pattern 2: Parallel Processing

Order Fulfillment:

  1. New order received
  2. Split into 3 parallel branches:
    • Verify payment
    • Check inventory
    • Calculate shipping
  3. Merge results
  4. IF: All validations passed? → Proceed with fulfillment

Debugging Workflows

Effective Debugging:
  1. Test node by node as you build
  2. Check execution history for patterns
  3. Use Set nodes to view intermediate data
  4. Add logging for analysis
  5. Name nodes descriptively

Practice Exercises

Exercise 1: Support Ticket Router

Route tickets based on priority and category

  • Urgent + VIP → Senior support
  • Technical issues → Tech team
  • Billing → Billing team
  • Others → General queue
Exercise 2: Approval Workflow

Purchase approval with escalation

  • Amount < $500: Auto-approve
  • $500-$5000: Manager approval
  • > $5000: Director approval
  • Wait 48 hours; if no response, escalate

🎉 Congratulations! Foundation Complete!

You've mastered:

  • ✅ Workflow automation concepts
  • ✅ Installing and navigating n8n
  • ✅ Working with nodes and data
  • ✅ Data manipulation with expressions
  • ✅ Complex workflow logic

Next: Take the Self-Evaluation Quiz!

Key Takeaways

  • IF nodes route data based on conditions
  • Switch nodes handle multiple routing paths
  • Merge nodes combine data from branches
  • Error handling is essential for production
  • Batch processing manages large datasets
  • Test incrementally and handle edge cases

Looking Forward

Before proceeding to Week 2 (Chapters 6-10), complete the Practice Workbook exercises and take the Self-Evaluation Quiz. These ensure you've mastered the foundations before advancing to core skills.

n8n Textbook | Chapter 5: Workflow Control and Logic

© 2025 IOLEBA | Dr. Marcus Lee

Originally Published: November 2025