How To Avoid Self-Triggering Of FLOW?

Problem

Consider a requirement scenario like below,

  • You need to create an approval flow on a SharePoint list
  • 4 levels of sequential approval
  • The FLOW should trigger on both created and modified events
  • You need to store response, signature, or timestamp of each approver immediately and it should reflect in the record.
  • User should be able to check the status of approval at any point of time
  • Also, user wants to update the record at any point during the approval process, and it should not trigger new workflow

To fulfill the above requirement, you must update the record/item on which FLOW has triggered. So, will it not trigger the same FLOW again? Check below warning message

How to Avoid Self triggering of FLOW

If you ignore the warning and do not take any action to avoid such self-trigger, then you will be in a trouble and if it’s a production environment then you will be in big trouble.

How can we avoid infinite trigger looping? What can we so that this update action should not trigger the same FLOW again?

Solution

What if we use a flag? Yes/No type column in the list or library? Set that flag to true or false and define the condition for FLOW trigger – trigger the flow only when flag is true. Is this possible? How can we do this? Yes, it’s possible. You can make use of trigger condition settings.

Make sure you create a Yes/No column in your list or library, set it Yes as default value.

Navigate to your FLOW –> Open menu option for trigger -> click on settings as shown below

How to Avoid Self triggering of FLOW

You would see Trigger Conditions section at the bottom -> Click on Add -> this is the place where we need to specify flag condition

As our flag column is of type Yes/No, we must define the condition as shown below. Make sure you use internal name of the column in below query.

@equals(triggerBody()?['RunFlow'],true)

You can use different kind of operators like and, or, not, etc and nested conditions as well. If you want to know more about trigger conditions, please refer this article over here.

Now once we have trigger condition set, while updating the item in the FLOW we just must make sure that we set the flag to false – so that it will not trigger the same FLOW again. Check below screenshot

If you have PowerApps interface, from where user updates the records, and you want the FLOW to get trigger on it then you must make sure that you set the flag to true explicitly.

So, whenever you want the FLOW to not trigger set the flag to false, and wherever you want it to trigger set it to true. You can also use this method to re-initiate the approval FLOW, just update the item with flag to true and it will re-initiate the approval FLOW.

This will really help where user wants to keep updating details/notes in the record irrespective of at what stage the approval process is. And of course this update should not trigger any FLOW.

Summary

As you see we can easily avoid self-trigger of the FLOW and avoid big mess. We can also add more conditions to avoid unnecessary flow runs, meaning - run the FLOW only on specific conditions.

Hope this will help you guys. Thanks for reading.


Similar Articles