Table of contents
The basics
There are two rules, when working with trigger conditions and they are similar to filtering and sorting data.
- Rule: Always use the internal column names for the SharePoint queries. These internal names are automatically set when you create a column. The internal name never changes, even we you change the name again (its only the display name then). You can check your internal names from the list or library settings.
- Rule: Respect the data type. If you are checking for a text field, use single quotes. If you are filtering for number, do not use single quotes. See examples below.
If you need to filter or order SharePoint columns, you can find their internal names here: List of Internal Names for SharePoint Fields | SoftArtisans
Comparison operators
The list of available expressions is pretty similar to the ones you can use with filter by queries. Anything that is a condition that ends in either true or false will work here.
Operator | Data type |
Equals | Text, Person, Number |
Contains | Text,Person |
Greater | Number, DateTime |
GreaterOrEquals | Number, DateTime |
Less | Number, DateTime |
LessOrEquals | Number, DateTime |
Empty | All |
Logical operators
If trigger conditions are put in each in their own row, they are combined as „AND“. If you want to specify more complex conditions use and, or, not.
Examples by data type
//string fields
@equals(triggerOutputs()?['body/Topic'], 'Work better with Microsoft Teams')
@contains(triggerOutputs()?['body/Topic'], 'Microsoft Teams')
//number fields
@equals(triggerOutputs()?['body/Price'], 50)
@greater(triggerOutputs()?['body/Price'], 50)
@greaterOrEquals(triggerOutputs()?['body/Price'], 50)
@less(triggerOutputs()?['body/Price'], 50)
@lessOrEquals(triggerOutputs()?['body/Price'], 50)
//single choice fields, multiple choice does not work with trigger conditions
@equals(triggerOutputs()?['body/Status/Value'], 'Approval in progress')
//single person fields, multiple person fields does not work with trigger conditions
@equals(triggerOutputs()?['body/Approver/Email'],'john@example.com')
//boolean fields if true
@triggerOutputs()?['body/Boolean']
//boolean fields if false
@not(triggerOutputs()?['body/Boolean'])
//The empty expression can be used to validate, if a column is filled or in fact empty. Perfect for use cases, where a flow can only run successfully if all necessary fields are filled.
@empty(triggerOutputs()?['body/Approver'])
//AND
@and(greater(triggerOutputs()?['body/Price'], 50),equals(triggerOutputs()?['body/Status/Value'], 'Approval in progress'))
//OR
@or(greater(triggerOutputs()?['body/Price'], 50),less(triggerOutputs()?['body/Price'], 10))
//NOT
@not(equals(triggerOutputs()?['body/Status/Value'], 'Approval in progress'))
Real world examples
Here are some more advanced examples to show what other expressions you can use in trigger conditions.
Recurrence
First “Tuesday” in a month
I recently had the challenge to create a recurring trigger, that only fires on every first Tuesday of the month. The first Tuesday of a month has to be within the first 7 days. By using utcnow(’dd’) you will get the number of the day. By using the expression Int() we get a whole number which we can then use to check if its less than 7. It can only be less than 7, because otherwise I would be the second Tuesday of the month.
@less(int(utcNow('dd')),7)
Only on work days (Monday to Friday)
The dayofweek() parameter will display a number from 0 to 6. 0 is Sunday, 6 equals Saturday.
@and(greater(dayOfWeek(utcNow()),0),less(dayOfWeek(utcNow()),6))
//or with two lines - multiple lines are automatically connected by AND
@greater(dayOfWeek(utcNow()),0)
@less(dayOfWeek(utcNow()),6)
Automated
SPO - Comparing the length of a multi-select person field to a fixed number
In this scenario I had a column containing multiple people (as approvers) and in another column the number of approvers who have finalized their approval. If the count of approvers matches the number in the finalized column I wanted to change the status of this list item. I used this trigger condition.
@equals(length(triggerOutputs()?['body/PersonMultiple']),triggerBody()?['PersonFinalized'])
SPO - Comparing fields against other fields
There might be scenarios where you will need to compare to fields to each other instead of fixed values. Lets say you have a list that contains a list of items that you have in storage. In that list you store three values: the current, the maximum and the minimum storage count. Using this expression you can trigger the flow whenever one of the items current storage count is below its allowed minimum.
@lessorequals(triggerBody()?['currentStorageCount'],triggerBody()?['minStorageCount'])
One more example to show that you can use other expressions as well. In this example we use a percentage for the minimum storage count instead of a number. We can use the expression mul() to calculate the percentage of the items maximum count and compare it to the current storage count. If it is lower that the calculated percentage, the flow will trigger. This way you can dynamically send out notifications to restock items.
@lessorequals(triggerBody()?['currentStorageCount'],mul(triggerBody()?['maxStorageCount'],triggerBody()?['minStoragePercent']))