title | description | services | ms.suite | ms.reviewer | ms.topic | ms.date |
---|---|---|---|---|---|---|
Add conditional statements to workflows |
How to create conditions that control actions in workflows in Azure Logic Apps |
logic-apps |
integration |
klam, logicappspm |
article |
10/09/2018 |
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.
-
An Azure subscription. If you don't have a subscription, sign up for a free Azure account.
-
Basic knowledge about how to create logic apps
-
To follow the example in this article, create this sample logic app with an Outlook.com account or a work or school account.
-
In the Azure portal, open your logic app in Logic App Designer.
-
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:
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.
-
In the search box, enter "condition" as your filter. Select this action: Condition - Control
-
In the Condition box, build your condition.
-
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.
-
In the middle box, select the operation to perform. For this example, select "contains".
-
In the right box, specify a value or field as your criteria. For this example, specify this string: Microsoft
Here's the 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.
-
-
Under If true and If false, add the steps to perform based on whether the condition is met. For example:
[!TIP] You can drag existing actions into the If true and If false paths.
-
Save your logic app.
This logic app now sends mail only when the new items in the RSS feed meet your condition.
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": {}
}
},
- For questions, visit the Microsoft Q&A question page for Azure Logic Apps.
- To submit or vote on features and suggestions, visit the Azure Logic Apps user feedback site.