Skip to content

Files

Latest commit

add3e34 · Feb 28, 2022

History

History
137 lines (100 loc) · 4.92 KB

logic-apps-control-flow-conditional-statement.md

File metadata and controls

137 lines (100 loc) · 4.92 KB
title description services ms.suite ms.reviewer ms.topic ms.date
Add conditions to workflows
Create conditions that control actions in workflows in Azure Logic Apps.
logic-apps
integration
estfan, azla
how-to
10/09/2018

Add conditions to control workflow actions in Azure Logic Apps

To run specific actions in your logic app only after passing a specified condition, add a condition action. 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 condition action 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 condition action:

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

Get support

Next steps