Logic Controls and Conditions

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 10 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Logic Controls and Conditions in Cloud Flows

Introduction: Why Logic Matters in Automation

When we talk about cloud flows—the automated workflows that connect our applications and services—we are essentially describing a digital assistant. An assistant that simply follows a linear, step-by-step list of instructions is helpful, but an assistant that can make decisions based on changing information is powerful. This ability to make decisions is what we call "Logic Controls and Conditions." Without these, every automation would be rigid, performing the exact same action regardless of the data it receives.

Logic controls are the mechanisms that allow your flows to branch, repeat, or pause based on specific criteria. They turn a static script into a dynamic process. Whether you are filtering incoming emails, processing approval requests, or syncing data between a CRM and a database, you need logic to handle the nuances of real-world scenarios. If a customer submits a high-priority ticket, you want the flow to alert a manager; if it is a low-priority request, you might just want it logged in a spreadsheet. This is the essence of logic.

In this lesson, we will dive deep into the building blocks of flow logic: Conditions, Switches, Loops, and Scopes. Understanding these will allow you to build complex, reliable automations that save time and reduce errors. By the end of this guide, you will be able to design flows that intelligently react to data, handle errors gracefully, and perform repetitive tasks with precision.


Not read yet

The Foundation: Understanding Conditions

A Condition is the most fundamental logic control in any automation platform. It works like an "If-Then" statement in programming. You define a rule, and the flow checks if that rule is true or false. Depending on the result, the flow follows one of two paths: the "Yes" path or the "No" path.

Anatomy of a Condition

Every condition consists of three parts:

  1. The Dynamic Content (Left side): This is the value you are testing. It usually comes from a previous step in your flow, such as an email subject, a status field from a database, or a numeric value from a form submission.
  2. The Operator: This defines the relationship between the dynamic content and your target value. Common operators include "is equal to," "is not equal to," "contains," "starts with," and "is greater than."
  3. The Target Value (Right side): This is the static or dynamic value you are comparing against. For example, if you are checking for high-priority tickets, your target value might be the string "High."

Callout: Conditions vs. Filters It is important to distinguish between a Condition block and a Filter. A Filter is often applied at the trigger level to stop a flow from even starting if the data doesn't match. A Condition block happens during the execution of the flow, allowing the process to continue even if the result is false, just down a different path. Use filters to save resources; use conditions to handle different business outcomes.

Practical Example: Routing Support Tickets

Imagine you are building a flow that triggers when a new help desk ticket is created. You want to route tickets based on the department mentioned in the ticket.

  1. Trigger: "When a new item is created" (e.g., in a SharePoint list).
  2. Action: Add a "Condition" control.
  3. Configuration:
    • Set the left side to the "Department" column from the SharePoint list.
    • Set the operator to "is equal to."
    • Set the right side to "Billing."
  4. Yes Path: Add an action to "Send an email" to the billing manager.
  5. No Path: Add another condition to check if the department is "Technical Support" or "Human Resources."

This structure prevents you from having to create separate, redundant flows for every single department.


Not read yet

Advanced Logic: The Switch Control

While a Condition is great for binary choices (Yes/No), what happens when you have four, five, or ten different paths? Creating nested conditions—placing a condition inside the "No" path of another condition—quickly becomes messy and hard to read. This is where the "Switch" control shines.

A Switch control allows you to map a single value to multiple potential outcomes. You provide an input variable, and the flow executes the case that matches that variable's value. If none of the cases match, you can define a "Default" path to handle unexpected inputs.

When to Use a Switch

Use a Switch when you have a single field that can contain one of many defined categories. For example, if you have a status field that can be "Pending," "In Progress," "Completed," or "Cancelled," a Switch is much cleaner than a series of nested "If-Then" blocks.

Step-by-Step: Implementing a Switch

  1. Select the Control: In your flow designer, add the "Switch" action.
  2. Define the On value: Choose the field you are evaluating, such as the "Order Status" from your database.
  3. Add Cases: Click "Add Case." For each case, define the value you are looking for (e.g., "Shipped").
  4. Add Actions: Inside each case, place the actions that should run specifically for that status.
  5. Set the Default: Use the "Default" block to handle any status that you haven't explicitly covered, such as "Unknown" or "Error."

Tip: Switch Limitations Unlike complex programming languages, most cloud flow Switch controls only support equality checks. You cannot use "greater than" or "contains" in a Switch. If you need those, stick to the standard Condition control.


Not read yet

Handling Repetition: Loops (Apply to Each)

Automation often involves processing lists of items. For example, you might receive an email with five attachments, or a database query might return a list of ten customers who have overdue payments. To handle these, you need a "Loop." In cloud flows, this is typically called "Apply to Each."

How "Apply to Each" Works

When you select an array (a list of items) as the input for an "Apply to Each" block, the flow will pause its main execution and iterate through every single item in that list, performing the specified actions for each one before moving on to the next step.

Practical Example: Sending Weekly Reports

If you have a list of employees who need a weekly performance report:

  1. Trigger: A scheduled "Recurrence" trigger (e.g., every Monday at 8:00 AM).
  2. Action: "Get items" from a SharePoint list containing employee email addresses.
  3. Control: Add "Apply to Each."
  4. Input: The output of the "Get items" step (the array of employees).
  5. Inside the Loop: Add a "Send an email" action. Use the "Email" dynamic content from the current item in the loop to send the report to each person individually.

Important Considerations for Loops

Loops are powerful, but they can be performance-heavy. If you have a loop that runs 5,000 times, your flow might take a long time to complete. Always try to filter your data before it reaches the loop to keep the list as small as possible.

Warning: Parallelism By default, "Apply to Each" runs sequentially (one item at a time). However, in many flow platforms, you can enable "Concurrency Control" in the settings of the loop. This allows the flow to process multiple items at once, significantly speeding up the execution. Be careful, though: if your actions involve updating a shared resource or database, running them in parallel might cause locking errors or race conditions.


Not read yet

Scopes: Grouping and Error Handling

As your flows grow, they become difficult to manage. A flow with 50 steps is a nightmare to debug. "Scopes" are a logic control used to group related actions together. Think of them as folders for your steps.

Why Use Scopes?

  1. Organization: Keeping related actions in a scope makes the flow easier to read and maintain.
  2. Error Handling (Try-Catch): This is the most important use case. By default, if one step in a flow fails, the whole flow stops. By placing actions inside a scope and then adding a subsequent action with a "Configure Run After" setting, you can catch errors.

Implementing a Try-Catch Pattern

  1. Add a Scope: Name it "Try Block." Place all your primary actions inside it.
  2. Add a Second Scope: Name it "Catch Block."
  3. Configure Run After: Click the three dots on the "Catch Block" and select "Configure Run After." Select "has failed" or "has timed out."
  4. Result: Now, if anything inside the "Try Block" fails, the flow will automatically jump to the "Catch Block," where you can add actions like sending an error notification to an administrator or logging the failure to a database.

Not read yet

Best Practices for Logic Design

Designing logic is not just about making the flow work; it is about making it sustainable. Over time, flows will be updated by others, and you want your logic to be clear enough that a teammate can understand it without needing a manual.

1. Keep Logic Flat

Whenever possible, avoid nesting conditions deep within other conditions. If you find yourself in a "pyramid of doom" where you have four or five layers of indentation, rethink your design. Can you use a Switch? Can you use a separate, smaller flow? Flattening your logic makes it much easier to debug.

2. Use Descriptive Names

The default names for conditions are often "Condition," "Condition 2," and "Condition 3." This is unhelpful. Always rename your condition blocks to describe what they are checking, such as "Check if Invoice is Overdue" or "Validate User Permissions."

3. Handle Empty Values

One of the most common causes of flow failure is trying to process a null (empty) value. If a field might be empty, always include a check to see if it is null before performing operations on it. Use the empty() expression in your conditions to handle this gracefully.

4. Document Your Logic

If a condition is complex, use the "Notes" feature (if available) or add a comment step if the platform allows it. Explain why the condition exists, not just what it is doing.

5. Limit Loop Depth

Avoid putting loops inside loops (nested loops) unless absolutely necessary. A loop inside a loop creates an exponential increase in execution time. If you have a loop of 10 items containing a loop of 10 items, you are performing 100 operations. If those numbers grow, your flow will likely hit timeout limits.


Not read yet

Common Pitfalls and How to Avoid Them

Pitfall 1: Type Mismatches

When comparing values, ensure they are the same type. Comparing a string (text) to an integer (number) often leads to unexpected results or flow failures.

  • Solution: Use expression functions like int() to convert a string to a number, or string() to convert a number to text, before performing the comparison.

Pitfall 2: The "Silent" Failure

Sometimes a flow fails, but the error isn't obvious because you didn't configure a failure path.

  • Solution: Always use the "Configure Run After" setting on your final cleanup or notification steps to ensure that even if the main process fails, you get an alert.

Pitfall 3: Over-reliance on Loops

Developers often try to use loops to perform tasks that could be done more efficiently with a single query.

  • Solution: If you are using a loop to find a specific item in a list, stop. Use a "Filter Array" action or an OData filter in your "Get Items" action instead. Let the system do the heavy lifting rather than manually iterating through items.

Not read yet

Quick Reference Table: Logic Control Comparison

Logic Control Primary Use Case Best For...
Condition Simple branching Binary (Yes/No) decisions.
Switch Categorical branching Choosing between 3+ static options.
Apply to Each Iteration Processing lists or arrays of data.
Scope Grouping/Error Handling Managing complexity and "Try-Catch" blocks.
Do Until Conditional Looping Repeating a task until a specific state is met.

Advanced Logic: The "Do Until" Loop

While "Apply to Each" is for processing lists, the "Do Until" loop is for processes that need to repeat until a specific condition is met. This is often used when waiting for a status to change.

Example: Waiting for an Approval

Suppose you have a process where you send an email to an external vendor, and you need to wait until they update a status field in your database to "Received."

  1. Action: Send the email.
  2. Control: Add a "Do Until" loop.
  3. Condition: Set the condition to "Status is equal to Received."
  4. Inside the Loop: Add a "Delay" action (e.g., wait 1 hour) and then a "Get Item" action to refresh the status from the database.
  5. Result: The loop will continue to run, checking every hour, until the database status changes to "Received."

Warning: Infinite Loops Always set a limit on your "Do Until" loops. Most platforms have a default limit (e.g., 60 iterations). If you don't set a timeout or a maximum count, an infinite loop can consume your flow execution quota very quickly and cause your account to be throttled.


Not read yet

Best Practices for Code and Expressions

Even in low-code environments, you will eventually need to use expressions to handle complex logic. Expressions are the functions you write inside the condition boxes.

Common Expressions to Master:

  • equals(a, b): Returns true if a equals b.
  • contains(text, substring): Returns true if the text contains the specified substring.
  • or(condition1, condition2): Returns true if either condition is met.
  • and(condition1, condition2): Returns true only if both conditions are met.
  • if(condition, valueIfTrue, valueIfFalse): A shorthand way to perform a condition directly within an expression.

Example: Using or in a Condition

Instead of creating two separate conditions to check if a department is "Sales" or "Marketing," you can use one condition with an expression: @or(equals(triggerBody()?['Department'], 'Sales'), equals(triggerBody()?['Department'], 'Marketing'))

This reduces the number of steps in your flow and makes the logic more compact.


Not read yet

Common Questions (FAQ)

Q: Can I stop a flow inside a loop? A: Yes, you can use the "Terminate" action. However, be aware that this will stop the entire flow, not just the current iteration of the loop.

Q: How do I handle date comparisons? A: Date comparisons can be tricky because of time zones. Always convert your dates to a standard format (like ISO 8601) using the formatDateTime() expression before comparing them.

Q: Is it better to use one large flow or many small flows? A: It is generally better to use smaller, modular flows. You can use the "HTTP" action or built-in flow triggers to call one flow from another. This makes testing and debugging much easier.

Q: How many conditions can I put in a single flow? A: There is no hard limit, but keep it reasonable. If your flow has more than 50-100 total actions, it is time to break it into child flows.


Key Takeaways

  1. Logic is the Brain of Automation: Use conditions and switches to transform static processes into intelligent, reactive workflows that handle different business scenarios.
  2. Choose the Right Tool: Use "Conditions" for binary logic, "Switches" for categorical logic, and "Loops" for processing collections of data.
  3. Prioritize Readability: Rename your actions and keep your logic flat. Avoid deep nesting to ensure your flows remain maintainable for future developers.
  4. Master Error Handling: Utilize "Scopes" and "Configure Run After" to create robust "Try-Catch" patterns that prevent silent failures and provide useful alerts when things go wrong.
  5. Optimize for Performance: Filter data before entering loops, use concurrency where appropriate, and always set limits on "Do Until" loops to avoid infinite execution.
  6. Use Expressions: Learn basic expression syntax (and, or, equals) to simplify your condition blocks and handle complex data transformations without adding extra steps.
  7. Think in Modules: If a flow becomes too large, break it down into smaller, reusable child flows. This improves performance and makes debugging significantly faster.

By mastering these logic controls, you are moving beyond simple task automation and into the realm of true process engineering. You now have the tools to build systems that are not just automated, but truly capable of managing the complexities of your business environment. Keep practicing, keep your flows clean, and always design with the future maintainer in mind.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.