Create conditional statements that control workflow actions in Azure Logic Apps

To run specific actions in your logic app only after passing a specified condition, add a conditional statement. This control structure compares the data in your workflow against specific values or fields. You can then specify different actions that run based on whether or not the data meets the condition. You can nest conditions inside each other.

For example, suppose you have a logic app that sends too many emails when new items appear on a website's RSS feed. You can add a conditional statement to send email only when the new item includes a specific string.

Tip

To run different steps based on different specific values, use a switch statement instead.

Prerequisites

Add condition

  1. In the Azure portal, open your logic app in Logic App Designer.

  2. Add a condition at the location that you want.

    To add a condition between steps, move the pointer over the arrow where you want to add the condition. Choose the plus sign (+) that appears, then choose Add an action. For example:

    Add action between steps

    When you want to add a condition at the end of your workflow, at the bottom of your logic app, choose New step > Add an action.

  3. In the search box, enter "condition" as your filter. Select this action: Condition - Control

    Add condition

  4. In the Condition box, build your condition.

    1. In the left box, specify the data or field that you want to compare.

      When you click inside the left box, the dynamic content list appears so you can select outputs from previous steps in your logic app. For this example, select the RSS feed summary.

      Build your condition

    2. In the middle box, select the operation to perform. For this example, select "contains".

    3. In the right box, specify a value or field as your criteria. For this example, specify this string: Microsoft

    Here's the complete condition:

    Complete condition

    To add another row to your condition, choose Add > Add row. To add a group with subconditions, choose Add > Add group. To group existing rows, select the checkboxes for those rows, choose the ellipses (...) button for any row, and then choose Make group.

  5. Under If true and If false, add the steps to perform based on whether the condition is met. For example:

    Condition with "If true" and "If false" paths

    Tip

    You can drag existing actions into the If true and If false paths.

  6. Save your logic app.

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

JSON definition

Here's the high-level code definition behind a conditional statement:

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

Get support

Next steps