This article is contributed. See the original author and article here.

Trigger conditions is a trigger setting used to specify one or more conditional expressions which must be true for the trigger to fire.


 


Trigger conditions can be set using logic app designer or manually using code view; for schema reference for trigger conditions, check the following link: Schema reference for trigger and action types – Azure Logic Apps | Microsoft Docs


 


To set trigger conditions using logic app designer, follow the steps below:


 


1- Go to your logic app.


2- On the trigger, click on the three dots () at the top right corner.


3- Select Settings.


4- Scroll down to Trigger Conditions.


5- Specify your conditional expression.


6-Click Done.


 


talsaifi_4-1620288562794.png


 


You can set single or multiple conditions as follows:


 


Single Condition


 


talsaifi_3-1620288463557.png


In this example, we apply trigger filter @not(equals(triggerBody().Size,0)) on the When a blob is added or modified (properties only) trigger settings under Trigger Conditions, so that the logic app is not triggered with empty files.


 


Multiple conditions


You can define multiple conditions but the logic app will only fire if all conditions are met. 


 


Two or more AND conditions


 


talsaifi_0-1620298102943.png


@not(empty(triggerBody())) and @contains(triggerBody()?[‘Name’],’.txt’)


This trigger will only fire if the trigger body is not empty and the file is a text file by checking if the name property contains ‘.txt’ extension inside the trigger body.


 


Two or more OR conditions


 


talsaifi_6-1620289993240.png


@or(greater(triggerBody()?[‘Age’],18),less(triggerBody()?[‘Age’],60))


This trigger will only fire if the age is greater than 18 or less than 60 by checking the age property inside the trigger body.


 


OR and AND Conditions together


 


talsaifi_7-1620290332938.png


@or(greater(triggerBody()?[‘Age’],18),and(less(triggerBody()?[‘Age’],60),equals(triggerBody()?[‘Fit’],true)))


This trigger will only fire if the age is greater than 18 or less than 60 and fit is true by checking the age and fit properties inside the trigger body.


 


For reference guide for logical comparison functions that can be used in conditional expressions, check the following link: Reference guide for functions in expressions – Azure Logic Apps | Microsoft Docs


 


Split On Behavior


If you apply it on a trigger with Split On enabled, the conditions are evaluated after the splitting which guarantees that only the array


elements that match the conditions are fired.


 


In this case, you will see one trigger event for each element in the trigger history, triggers that did not fire due to trigger conditions will be found in Trigger History.


 


talsaifi_1-1620293690288.png


 


Pros



  • Simple logic app with less steps by moving logic that would usually be inside the logic app to define if the logic app can be executed or not to inside the trigger itself.

  • Clean workflow run history that reduces operational burden by eliminating unwanted runs.

  • Reduced costs by reducing the action calls made for checking the conditions within logic app.


 


Cons



  • Trigger conditions are not visible which make it hard to troubleshoot; so, it is recommended to modify trigger name to indicate that there are trigger conditions set.

  • Adding trigger conditions does not support intellisense; so, it is recommended to draft your expression within an initialize variable or compose action, note that in these actions, an @ is not needed at the beginning of the expression, but within trigger conditions it is needed

  • Runs that did not meet the trigger conditions will not show in the runs history.


 

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.