Categories
Office 365 Power Automate Sharepoint Tips

Power Automate SharePoint Update Loop

“Actions in this flow may result in an infinite trigger loop” when updating the same list item on the “When an item is created or modified” trigger.

In this scenario, Power Automate will enter an infinite loop as the actions in the flow trigger a new instance of the flow. SharePoint Designer workflows internally prevented this scenario so this guide will explain how to achieve the same in Microsoft Power Automate.

To prevent an infinite loop, we create a specific user context to run the PowerAutomate updates on the list item, then we add a trigger filter to prevent new flows from starting when started by the Power Automate user.

First, add a user in the Office 365 Admin Centre

For the purpose of this example, I will call the user Power Automate.

Then the user needs to be assigned a Power Automate license (a free license is fine for many environments) and the relevant permissions on the SharePoint site that the flow will be running on.

Then you want to assign the “Update item” action to the new user you have created.

At this point, it’s worth saving and testing your flow and letting at least 2 iterations of the loop cycle through before stopping it and opening the second iteration. You will want to open and check the output.

In this scenario, I haven’t purchased an exchange license for the user so I don’t have a value for body/Editor/Email which would be preferable, so I will use body/Editor/DisplayName

"Editor":{"@odata.type":"#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser","Claims":"i:0#.f|membership|powerautomate@devpros.com.au","DisplayName":"Power Automate","Email":null,"Picture":null, "Department":null,"JobTitle":null}

Now that we have targeted the element we are identifying, let’s create the trigger condition by editing the settings on the flow trigger.

We will create a trigger condition and enter the expression to check if the user who modified the item was the Power Automate user we created and assigned to the step.

@not(equals(triggerOutputs()?['body/Editor/DisplayName'],'Power Automate'))

This would read in English as; The trigger output value extracted from body/editor/displayname is not equal to ‘Power Automate’

The result of this condition should be true for the flow to initialise.

Once you save and turn your flow back on, upon testing you should see each time a list item is updated, a single instance of the flow run.

Optional

If you don’t observe the desired outcome, I would recommend creating a couple of steps in your workflow to check the output of the expression.

First, check the output of the desired field by initialising a variable (initialize variable).

triggerOutputs()?['body/Editor/DisplayName']

Then check the output of your boolean condition by initialising another variable (initialize variable).

not(equals(triggerOutputs()?['body/Editor/DisplayName'],'Power Automate'))

Save and turn the flow back on. Update the list item and once at least 2 iterations have passed, stop the flow and check the second iteration.

This is the expected result, we can see the value of DisplayName is ‘Power Automate’ and the expression is false, which means with the trigger filter added, it will not run on this trigger. This information should assist you with troubleshooting the issue.