How to avoid infinite loops using conditional triggers in Power Automate.

 This is one of the most common scenarios. 

What happens is your Power Automate flow gets triggered on SharePoint list on item creation or modification. And then you have a condition in the flow which updates the same SharePoint list item column. But since the flow gets triggered on SharePoint list item modification the flow kicks in again. This sets the flow to be in infinite loop condition, where it gets triggered on item modification and its body is updating the same SharePoint list item.




Now, to fix this we have to use conditional triggers.

The logic behind this is that your flow should run via your service account. And then the update item action in the flow will also happen using the same service account. 

We can then put in a condition that if the modifications to SharePoint item happens using this service account, the conditional trigger will prevent the flow to initiate.

Lets dig into this now.


what we are doing in here is 

not(equals(triggerBody()?['Editor']?['Email'],'serviceaccountemailID'))

what the above formula does is, it fetches all modifications done using the service account. Then we append not  to it as we only want the flow to be triggered when the end user does modifications and not when the service account does the modifications. This is because service account will modify only when you have the update item action in the flow body.

Please note we then copy the above formula, and open the settings for the starting point of your flow,

in our case it is When an item is created or modified.



Then click on the last option Trigger Conditions, as shown below



Paste the copied formula in here adding @ in the beginning.


@not(equals(triggerBody()?['Editor']?['Email'],'serviceaccountemailID'))
 
Now this is to prevent the flow to be triggered when the service account makes modifications in the list.

Comments

Popular posts from this blog

Creating Nested Galleries in Power Apps. (Parent-Child Relationship)

How to reset a datepicker control in PowerApps?

Reset () function failing to work on Edit form for Combo boxes in Power App.