
Module 5 Lesson 1: Complex IF Logic
Master multi-condition decisions. Learn how to use AND and OR logic in n8n expressions to build 'Smart' workflows that react to complex real-world scenarios.
Module 5 Lesson 1: Complex IF Logic
In Module 3, we used a simple IF node. But real decisions are rarely "One thing."
- "If the price is > $100 AND the customer is from the UK."
- "If the email is from 'boss@company.com' OR it has the word 'URGENT'."
1. Using AND (&&)
All conditions must be true.
{{ $json.price > 100 && $json.country === 'UK' }}
2. Using OR (||)
At least one condition must be true.
{{ $json.sender === 'boss@company.com' || $json.subject.includes('URGENT') }}
Visualizing the Process
graph TD
Start[Input] --> Process[Processing]
Process --> Decision{Check}
Decision -->|Success| End[Complete]
Decision -->|Retry| Process
3. The "Grouped" Logic (Parentheses)
You can combine them!
{ ($json.price > 1000 || $json.isVIP) && $json.status === 'paid' }
- This says: "If they are rich (price > 1000) OR they are a VIP, AND they have already paid... then proceed."
4. The "Inverse" Logic (!)
"Is this NOT a test?"
{ !$json.is_test_mode }
Exercise: The Logic Puzzle
- Write an expression for: "The user must be over 18 and have a verified email."
- Write an expression for: "The order is either 'Shipped' or 'Complete'."
- Write a complex expression: "If the day is Monday AND (the hour is 9 or the hour is 10)." (Hint: Use
new Date().getDay()andnew Date().getHours()). - Why is it better to do complex logic in a Code Node if you have more than 3 conditions?
- Search: What is the "Compare" node (deprecated) vs the new "IF" node?
Summary
Complex logic turns a "Workflow" into a "Thinking Assistant." By mastering AND, OR, and NOT, you can build automations that handle the messy, multi-faceted reality of business data with precision.
Next Lesson: Processing the many: The Split In Batches Node.