Muokkaa

Jaa


Add conditions to control workflow actions 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 logic app workflow in the designer.

  2. Follow these general steps to add the Condition action to your workflow.

  3. 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.

      When you select inside the Choose a value box, the dynamic content list opens automatically. From this list, you can select outputs from previous steps in your workflow.

      This example selects the RSS trigger output named Feed summary.

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

    2. Open the middle list, select the operation to perform.

      This example selects contains.

    3. 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 complete condition now looks like the following example:

    Screenshot shows the Consumption workflow and the complete condition criteria.

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

    • To add a group with subconditions, from the Add 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.

  4. 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.

  5. 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"
         ]
      },
   }
},

Next steps