cancel
Showing results for 
Search instead for 
Did you mean: 
Michal

Trigger conditions - filling the information gap

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:

 

 

 

 

@contains(triggerBody()?['subject'], 'Update')

 

 

 

 

 

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.

img3.png

@and(

(body contains "Community"),

or(

(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'

OR

'Severity: 2' AND 'Priority: 2'

AND

subject contains "New" 

OR 

subject contains "Close"

 

When I first enter the flow I saw this condition:

 

Img1.png

 

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:

img2.png

 

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. 

 

Conclusion

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. 

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/