Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

How to cancel running Power Automate flow when a file was modified

Posted on July 13, 2022July 17, 2022 by Tom

“I’d like to restart the approval process when somebody modified the file in SharePoint, how can I cancel the running Power Automate flow to start a new one?”


If you use Power Automate to build approval processes, you want to make sure that everyone approves the same file in the same version. You could hardly call it a reliable solution if somebody changes the file in the middle of the process.

The best solution would be to remove all edit permissions right after you start the approval, but if you decide not to do that, you might at least cancel the running approval process. And this article will show you how to do that.

Keep the running flow id

The flows in Power Automate don’t know about each other. It can easily run 10 processes on the same document and be fine with that. Therefore, if you want to know about a running flow, you must keep the information yourself.

If you’re working with SharePoint document library, you can add one extra column, e.g. RunningFlowID.

Alternatively you could use also a separate SharePoint list to keep the information.

In both situations you want to store the flow run id in the column using an expression.

workflow()?['run']['name']
Power Automate cancel flow modified

Cancel the running flow

Once you have the id you can easily see if there’s already a running flow. If the column has a value, there’s already a running flow to cancel.

Power Automate has a dedicated action that’ll do that – in the ‘Power Automate Management’ group ‘Cancel Flow Run’.

The action has 3 inputs: the environment, flow, and run id. The environment and flow will be fixed, while the run id is the id you stored in the previous step.

You just cancelled the running flow and you can continue with the next steps in the flow. Just make sure to run the flow only if there’s an update by the user and avoid the infinite trigger loop!

Power Automate cancel flow modified

Summary

You can cancel a Power Automate flow when an item or document is modified and run a new one, but you must keep the flow run id somewhere. Once you have the current flow id Power Automate will let you cancel that flow at the beginning of the new instance. Reset the status, empty the approval history and start from the beginning.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with 1000s of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes