Have you seen the following error in your Power Automate?
“Actions in this flow may result in an infinite trigger loop. Please ensure you add appropriate conditional checks to prevent this flow from triggering itself.“
If your answer is yes, then please keep reading…
As you can see the warning is telling you “it may” and you need to “add appropriate condition checks”.
So to demonstrate that, I am going to create a scenario to get this warning and address it. I will create a simple custom list (named InfiniteLoop) with a default ‘Title’ field. Then I will create a flow with a trigger “When an item is created or modified”. In this flow, I will use a random number generator function rand to generate a random number from 1 to 75. The flow will append the generated random number to the Title field and call Update item.
After all that, it will show me a warning in the Flow checker as seen below.
# code for the compose is concat ( ' ' , rand(1,75)) # code for the Update 'Title' is concat ( triggerOutputs()?['body/Title'], outputs('Compose'))
Step By Step Solution
There are multiple ways to solve this infinite loop issue.
You need to add a trigger condition to your flow so it only fires when condition is met and does not fire back again after update item in your flow.
Solution # 1 : Utilize ‘Modified By’ field as the trigger condition.
Basically, what you want here is to set a trigger condition to check “Modified By” Email is NOT equals to a user’s email(flow author’s email). In my scenario BobK created the flow.
You can simply copy paste the following formula to the Trigger Condition, and change the email address appropriately.
# First modify by check email is null, # if yes, return true # if no, convert to lower case and compare to flow author # Make sure to change the email address after copy and paste @if(equals(triggerOutputs()?['body/Editor/Email'],null), true, not(equals(toLower(triggerOutputs()?['body/Editor/Email']),'firstname.lastname@example.org')))
NOTE: Please make a note, if the Flow Author user makes a change to the list item, the flow will not trigger. This is a downside of this technique. If you are a flow author and you will not be end user to update the list items this technique will work great for you.
Solution # 2 : Create a Copy of the field to do compare.
In this technique for above summarized scenario. I will create a new field e.g. “Title_Copy”. This field will hold the copy of the data from the “Title” field. The new Title_Copy field will be hidden from the user. The copy will be made in the flow with update item.
The flow will have a trigger condition to check if the “Title” and “Title_Copy” are NOT equal. If they are not equal that means the user has made the change to the Title field. So allow flow trigger to fire.
If they are equal that means the change is made by the flow at the time of the update. So do not allow trigger to fire.
# To fire the trigger, check if the Title and Title_Copy are NOT equal. @not(equals(triggerOutputs()?['body/Title'],triggerOutputs()?['body/Title_Copy']))
Solution # 3 : Create a Copy of the field to do compare for more than one fields.
So far ok if you were only interested in the one field user makes the modification. What if you have more than one field which your flow is interested to check whenever a user makes a modification. The above #2 technique may need to be adjusted.
Basically, you will make a master Copy filed with multi text type. This field will be hidden similar to the #2 solution. This field also will be updated in the flow.
But update will be concatenation of the all required fields your flow want to trigger on.
To be continued… (I will complete this later as I get time)
As you can see there are multiple ways you can avoid infinite loop. Please let me know your comments.