I am trying to resolve this error in 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.
This seems to be a common problem when using this trigger:
When an item is created or modified
where the associated flow contains this action:
The dynamic is succinctly explained in these videos here and here.
Desired Behaviour
The desired behaviour is that the flow:
Runs when a list item is created or modified by a user (and updates the item accordingly)
But not when the flow itself updates the item
Actual Behaviour
The actual behaviour is that the flow:
Runs when a list item is created or modified by a user (and updates the item accordingly)
Also runs when the flow itself updates the item (causing an infinite loop)
What I've Tried
Some posts suggest using a Service Account
to run the flow and then apply the logic:
- If the flow was triggered by a Service Account, terminate the flow
But I do not have access to a service account in this scenario.
The simplest solution seems to be answers like this one and this one.
They suggest creating a column in the SharePoint List to store a 'flag'.
I understand the concept of using flags to indicate:
- DO run the flow if
SOME_FLAG
isfalse
- DO NOT run the flow if
SOME_FLAG
istrue
But I am having trouble when it comes to implementing them properly in this scenario.
Specifically, I have added a Yes/No
column to my List called LastModifedByFlow
.
The default value is No
(i.e. false
).
My flow is structured like this:
01) TRIGGER:
When an item is created or modified
02) I have added this Trigger Condition
@equals(triggerBody()?['LastModifiedByFlow'],false)
03) This means the flow will run when LastModifiedByFlow
is false
04) Create some variables
05) ACTION:
Update the item - this includes setting the LastModifedByFlow
value to true
Question
The first time the flow runs, it works great:
- the item is updated
- the item's
LastModifedByFlow
value is set totrue
so the flow doesn't run again
But how and where in the flow do I set the LastModifedByFlow
value back to false
?
So that the flow will run each time a user subsequently modifies the list item?