Edit

Share via


Add conditions to control workflow action execution in Azure Logic Apps

Applies to: Azure Logic Apps (Consumption + Standard)

When you want to set up a condition that returns true or false and have the result determine whether your workflow runs one path of actions or another, add the Control action named Condition to your workflow. You can also nest conditions inside each other.

For example, suppose you have a workflow that sends too many emails when new items appear on a website's RSS feed. You can add the Condition action to send email only when the new item includes a specific word.

Note

If you want to specify more than two paths from which your workflow can choose or condition criteria that's not restricted to only true or false, use a switch action instead.

This guide shows how to add a condition to your workflow and use the result to help your workflow choose between two action paths.

Prerequisites

Add a condition

  1. In the Azure portal, open your Consumption logic app resource.

  2. On the sidebar menu, under Development Tools, select the designer to open the blank workflow.

    This example uses the RSS trigger named When a feed item is published to start the workflow. However, you can use any trigger that you want in your own scenarios.

  3. Add the trigger that you want by following the general steps to add a trigger.

  4. Add the Condition action to your workflow by following the general steps to add an action.

  5. In the Condition action, follow these steps to build your condition:

    1. In the left-side box named Choose a value, enter the first value or field that you want to compare.

      After you select inside the Choose a value box, the options to open the dynamic content list (lightning icon) or expression editor (formula icon) appear.

      Screenshot shows Azure portal, Consumption workflow designer, RSS trigger, and Condition action with information pane open, and dynamic content button selected.

    2. Select the lightning icon to open the dynamic content list.

      From this list, you can select outputs from previous steps in your workflow. This example selects the RSS trigger output named Feed summary. If you don't see this option, you might need to select See more.

      Screenshot shows Azure portal, Consumption workflow designer, RSS trigger, and Condition action with criteria construction.

    3. From the middle box, select the operation to perform.

      This example selects contains.

    4. In the right-side box named Choose a value, enter the value or field that you want to compare with the first.

      This example specifies the following string: Microsoft

    The following example shows the complete condition:

    Screenshot shows the Consumption workflow and the complete condition criteria.

    • To add another row to your condition, from the New item menu, select Add row.

    • To add a group with subconditions, from the New item menu, select Add group.

    • To group existing rows, select the checkboxes for those rows, select the ellipses (...) button for any row, and then select Make group.

  6. In the True and False action paths, add the actions that you want to run, based on whether the condition is true or false respectively, for example:

    Screenshot shows the Consumption workflow and the condition with true and false paths.

    Tip

    You can drag existing actions into the True and False paths.

  7. Save your workflow. On the designer toolbar, select Save.

This workflow now sends mail only when the new items in the RSS feed meet your condition.

JSON definition

The following code shows the high-level JSON definition for the Condition action. For the full definition, see If action - Schema reference guide for trigger and action types in Azure Logic Apps.

"actions": {
   "Condition": {
      "type": "If",
      "actions": {
         "Send_an_email_(V2)": {
            "inputs": {},
            "runAfter": {},
            "type": "ApiConnection"
         },
      },
      "expression": {
         "and": [ 
            {
               "contains": [ 
                  "@triggerBody()?['summary']",
                  "Microsoft"
               ]
            }
         ]
      },
      "runAfter": {
         "Condition": [
            "Succeeded"
         ]
      }
   }
},