User Review
( votes)Microsoft Power Automate Flows are the recommended path forward for extending business logic that traditionally was extended using Plugins and Workflows.
For code execution trigger we were only offered message as an option and in case of the update message a step forward to choose the fields that need to be updated for the plugin or workflow to be executed.
However if we wanted to get the code to execute/trigger based on a certain value, we had to check for that condition within the code or as a step in the workflow which means the workflow or the plugin code would always trigger.
Power Automate Flows has a very powerful feature that helps cover this limitation of plugins and workflows and thereby reduce unnecessary execution of the flows. Do note that while the direction from Microsoft is to move to Flows for biz logic extensions, unlike plugins or workflows where there were no limits to the count of workflow jobs available for execution, Flows depending on the plan that you have subscribed to are limited in number. This makes it all the more important to prevent unwanted flow executions.
Trigger Conditions for Trigger Steps
Let us have a look at how the trigger conditions can be specified. In the example below we have used the update trigger of the Common Data Service (Current) connector, you could apply trigger condition on any connector and trigger too. This is a part of the Power Automate platform framework.
Start with the Create/Update trigger as shown below
Once added, click on the setting
In the trigger conditions you could specify flow expressions that evaluate to true and false. As you can see in the screenshot, you could provide one or more expressions, if you add more than one expression, it is an AND between them, which means all expressions provided should evaluate to TRUE for the trigger to execute.
Let us have a look at this expression
@equals(triggerbody()?[‘prioritycode’],1)
This checks if the priority code of the record for which the action is triggered is set to 1. Since it is an optionset type of field we have used the integer value.
Alternatively, you could compare with the optionset labels using the second example shown above
@equals(triggerbody()?[‘_leadsourcecode_label’],’Advertisement’)
Instead of an AND if you would have liked an OR between the two conditions, you could rewrite this as
@or(@equals(triggerbody()?[‘prioritycode’],1),@equals(triggerbody()?[‘_leadsourcecode_label’],’Advertisement’))
Check for the various operators supported here
Filter Expression in Common Data Service (Current) Trigger
While trigger condition is a part of the Power Automate framework and is available for all connectors and their triggers, Microsoft has added an easy way to specify the trigger condition for the Common Data Service (Current) connector.
You now see Filter Expression as one of the options to be specified in the trigger properties.
This works similarly to the trigger condition but requires the filters to be specified in ODATA format that we CDS developers are used to.
Unless the filter expression evaluates to true, the trigger will not be fired and it will not account towards the flow execution limits set.
Conclusion
Make use of trigger conditions to design efficient flows and avoid unnecessary executions.