One of the commonly used triggers in a flow is "When a new email arrives".
The set of fields is very simple and it might be difficult to catch particular and only the one mail you so much care about.
I have seen people building flows that are triggered on more emails than necessary and have huge conditions inside, testing if the mail which triggered the flow meets their requirements. It is not an efficient use of Power Automate to say at least.
There is a more simple way, a bit hidden from your eyes. You can use Settings and Trigger Conditions.
You can put several condition expressions, and you may wonder what an operator is used between them? You won't know unless you test it (unfortunately). I have already tested it for you and the answer is AND. So each line of Trigger conditions must return TRUE in order to execute the trigger.
Before we jump into building conditions there is a good article I can recommend you read: Power Automate Trigger Conditions made EASY by @MattWeston365. It is a good intro to how you can actually test your conditions.
Further down I will explain to you how to build trigger conditions
When building trigger conditions start with @ followed by functions. You can find the list of available functions in expressions in the Reference guide to using functions in expressions for Azure Logic Apps and Power Automate.
A simple expression to test if the subject of the mail contains the word "Update", would look like:
If you would like to test if the subject of the mail contains the word "Update" or "Weekly", then the expression would be like this:
@or(contains(triggerBody()?['subject'], 'Update'),contains(triggerBody()?['subject'], 'Weekly'))
How about checking the subject and the mail body? To test if the subject of the mail contains the word "Update" or "Weekly", and the body contains a string "Community", the expression would look like this:
@and(or(contains(triggerBody()?['subject'], 'New'),contains(triggerBody()?['subject'], 'Closed')),(contains(triggerBody()?['body'], 'Community')
It is getting more complex so let me visualize it using the conditions within the flow and converting it into trigger conditions.
(body contains "Community"),
(subject contains "Update"),
(subject contains "Weekly")
To better understand those conditions, here is a real-life use case.
In IT Operations there is a SCOM server that monitors the infrastructure. One of the methods for subscribing to Alerts and Warning events notification is by sending them out by mail. There was some specific sort of mails coming from SCOM which should be checked and based on them an action should be triggered.
The requirement was to catch all mails with Severity 2 and Priority 1 or Severity 2 and Priority 2. In addition, the subject should contain words: 'New' or 'Closed'. Severity and Priority are in the body of the message.
Here is the condition in a more readable format.
'Severity: 2' AND 'Priority : 1'
'Severity: 2' AND 'Priority: 2'
subject contains "New"
subject contains "Close"
When I first enter the flow I saw this condition:
Pretty complex, right? And the flow was running on every mail from hundreds coming from SCOM every day.
Here is how you can do it using trigger expressions
Remember that there is an AND operator between each expression. Having this in mind let's break the above into two trigger expressions lines.
In the first expression, we will focus on the Severity and Priority. In the second expression, we will test a subject.
The first expression will look like this:
@or(and(contains(triggerBody()?['body'], 'Severity: 2'),contains(triggerBody()?['body'], 'Priority: 1')),and(contains(triggerBody()?['body'], 'Severity: 2'),contains(triggerBody()?['body'], 'Priority: 2')))
Add a second expression:
@or(contains(triggerBody()?['subject'], 'New'),contains(triggerBody()?['subject'], 'Close'))
Combined in the flow, in the trigger condition this will look like this:
This way the flow has been triggered a few times a day compared to some hundred times before.
Here is a little challenge for you!
Based on this article. would you be able to convert this example into one expression? If yes, share it with us within the comment below this article.
Sometimes pictures and samples can explain a complex topic better than a thousand words. I hope that in this case, my example helped you to understand how to build trigger conditions in your future flows. If not, let me know and I will try to explain it better.
If you recently build an interesting condition, please share it with us in the comments below, so more can get inspiration from your work.