The Infinite Loop: What It Is and How to Avoid It

Lately infinite loop in Microsoft Flow has been rearing its ugly head so I want to take a minute to explain what it is and how to avoid it. Flow is a powerful tool that gives power users the opportunity to build solutions, both simple and complex. The flip side of this is that with great power comes great responsibility. The infinite loop is one of those things you can accidentally do with flow and make quite a mess.

What it is

The infinite loop is when you set a flow to trigger when data is updated or modified, then in that same flow you update that same trigger data thus causing your flow to trigger over and over and over again.

Why is this such a big deal?

A few weeks ago I accidentally created over a hundred flow approvals in my environment. My flow kept triggering and creating them. It happened very quickly. The only way to get rid of them is to manually take action on each one or to write a PowerShell script to do it. This means you need to know how to write PowerShell scripts AND you need to be an administrator in your environment. Someone else I know also recently created hundreds of Microsoft teams in their environment by triggering the creation based on a SharePoint item being created or modified. The flow updated that item and just kept creating teams all with the same name but different GUID. Again PowerShell is the only way to delete these hundreds of teams.

Note: There might be other ways to quickly delete flow approvals and teams that I haven’t heard of, but I am going to bet they will not be easy fixes.

How to avoid infinite loop

To avoid the infinite loop you need to create a separate data field that updates when a flow runs. Then add a condition to only run if the value for that field is not equal to whatever you are setting it to.

Here is an example shown in the flow below.

* This flow is triggered when an file in a SharePoint library is created or modified.

*The flow checks if the file is ready for review using a condition to check a field.

*If this condition is met, two consecutive approvals are created.

*The SharePoint item is then updated to include the approval info; who approved and the date

NO INFINITE LOOP! 

flow avoid infinite loop       Here are some other solutions that community members have offered: 

Michael Svenson: Disable Event Firing when Flow Updates a SharePoint List Item

John Liu: Modifying Modified by and Modified Time with Microsoft Flow

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s