This is just a very short post explaining how to add conditions within your Azure Logic App. The most common case would probably handle a scenario where it’s required to execute different follow-up actions based on the execution status of the preceding action (success or failure). And therefore I will be using this case as an example. But let’s go over some of the details first.
Azure Logic App – Conditions: Expressions & Dependencies
Update: This article is still relevant! However, due to the latest designer updates, the screenshots aren’t reflecting schema version 2015-08-01-preview. More information can be found here.
Conditions are basically an array of checks that have to be met before an action will execute. They can either be expressions that evaluate to either true or false at runtime, or implicit and explicit dependencies.
Implicit dependencies are created by the Azure Logic App Service in case an Action consumes data returned by another Action. Implicit dependencies will show up within the code view, but you won’t have to worry about managing implicit dependencies as expected.
Explicit dependencies can be used in case you would like to wait for another action to complete however, not having a dependency on the returned data. I’ve included a sample below which can only be inserted while in code view mode.
It’s important to know that adding a depends on will cause the action to only execute if / when the dependency succeeds. This is also the reason why it’s so important to check for the action failure state within the Logic App workflow.
The syntax used to build expressions is also known as the Logic App Workflow Definition Language. It’s a very simple language and includes functions to handle collections, strings, dates and logic just like in any other language. More details can be found here: https://msdn.microsoft.com/en-US/library/azure/dn948512.aspx
NOTE: At the moment the Azure Logic App designer doesn’t include a rich expression builder (and I’m not sure it ever will) and therefore it’s required to type your expressions within a Condition text box as shown below;
It’s possible to create multiple conditions instead of building very complex expressions. This will look like the following:
Or just combine the two using the
Building the sample workflow
At this point it’s time to start building a simple Azure Logic App which includes the success/failure check. I will keep all simple as possible by using only HTTP actions and no triggers.
- Create a new Logic App within an existing App Service Plan (or create a new App Service Plan and provision some Azure API Apps). Open the Logic App and click on Triggers and Actions to open the designer/ author mode.
- I won’t be using triggers and therefore selecting the Run this logic manually checkbox.
- At this point add a new HTTP action, select GET and type http://www.microsoft.com within the URI text box.
- Open http://requestb.in and create a new RequestBin which will be used to track our success and failure calls. The URL will look something like this
- Add another HTTP Action, select GET and provide the requestBin url however adding a query string parameter like so:
- Before saving, make sure to click on the gear icon in the right upper corner and select Add a condition to be met. A text box will show up with the caption Condition. Provide the expression as shown below and save the action.
- Add a third HTTP action and repeat the steps as mentioned within step 5 and 6, but this time providing the following URI
http://requestb.in/1hyc6ss1?result=failureand the following expression as a condition:
NOTE: As soon as you save the action you will notice that the designer is smart enough to rearrange the logic steps.
- Save the workflow and open the main properties screen of the Logic App. In this blade press Run Now
At this point it’s time to review what happened. A section called Operations can be found within main properties screen. Here you can review information about the execution of the Azure Logic App. If you select the latest entry, a new blade will appear on the right containing the details.
In the details view it’s visible that http1 (the failure action) was skipped. This indicates that the Microsoft website was up and running.
By clicking on the individual actions it’s even possible to review the input and output of the call, which is very useful for debugging. At this point you should also be able to see a success request listed within your RequestBin.
This post just quickly covered how to work with conditions within Azure Logic Apps. As you can see it’s very simple to create conditions using dependencies or expressions.