Stopping Infinite Loops When Updating SharePoint List Items

Power Automate is well integrated with SharePoint.  I believe that it can now be considered a reasonable “successor” to SharePoint Designer workflows.  That said, there are some areas where it could be improved. Specifically, if a Flow runs when a SharePoint list item is updated and the Flow also updates the same item, you have an infinite loop.  The actions of one instance of the Flow spawn another, and so on.  The good news is that there is a simple way to work around or resolve this issue.

My solution leverages a hidden SharePoint Multi-line text column with append text set to on.  This column is always empty when you create or edit an item, but you can always view entries made in previous edits.  The key is that the column is empty on every edit unless you explicitly populate the column.  I am leveraging this feature as a type of “flag”.  Every time I use the Update item action in my Flow, I enter text in the multi-line text column.  The only time there will be data in that column is if it is put there by Flow.  When a user edits the list, the column is hidden, and they cannot enter data.  I add a trigger condition that evaluates to true when the column is empty.  So, the Flow will never run when the last edit was done via a Flow because the column will never be empty.

Here are some brief instructions on how to test my solution:

  1. Create a Custom list
  2. Turn on versioning in the list
  3. Add a multi-line text column to the list
    1. Set the column to plain text
    2. Set “append text” to on
    3. Hide the column
  4. Create a Flow that uses the SharePoint “When a list item is created or modified” trigger and a SharePoint “Update Item” action
    1. Add an expression in the trigger condition that evaluates to true if the multi-line text column is null
      1. Example: @equals(triggerBody()?[‘MyColumn’],null)
    2. Configure the Update item action to update item that fired the trigger
      1. Include some text in the multi-line text column
    3. Test your Flow by creating and editing a list item
      1. The trigger should fire once when the item is created and once for each edit of the item

If you need step by step instructions, read on….

How to turn versioning on:

  1. Create a Custom list
  2. Go to list settings
  3. Click on Versioning settings
    1. Set “Create a version each time you edit an item in this list?” to Yes image002
  4. Click on OK

How to add and hide an “append text” column

  1. Go to list settings
  2. Click on “Create column”
    1. Name the column “StopRun”
    2. Select “Multiple lines of text”
    3. Select “Plain text”
    4. Set “Append Changes to Existing Text” to Yes

image004

How to make the column hidden

  1. Go to List settings
  2. Click on “Advanced settings”
  3. Set “Allow management of content types” to Yes image005
  4. Click on “OK”
  5. Scroll down the page and click on Item under Content Types Item
  6. Click on the StopRun column title image007
  7. Select “Hidden” and then click on “OK” Hidden
  8.  Go back to Advanced settings and set “Allow management of content types” to No

How to create the Trigger condition

  1. Create a Flow using the SharePoint When an item is created or modified trigger
    1. Click on the ellipses in the top right corner of the trigger and then click on settings image011
    2. Click on “Add” at the bottom under Trigger Conditions
    3. Paste the following into the Trigger Condition text box and click on “Done”:
      1. @equals(triggerBody()?[‘StopRun’],null) TriggerCondx
      2. The expression checks to see if the StopRun column is null
        1. If you named your column anything other than StopRun, you can replace StopRun with the internal name of your column
    4. Add a SharePoint Update item action
      1. Select your site and list and configure the action per the screen shot below image015

How to test your Flow

  1. Create a new list item
    1. Your Flow should run once
  2. Edit the list item
    1. Your Flow should run once

Leave a Reply

Fill in your details below or click an icon to log in:

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