Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
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 *

Now available:

The Ultimate Power Automate expressions cheat sheet
Equip yourself with the tool to translate your thoughts into Power Automate expressions!

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.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Check if email already exists in Outlook contacts (Power Automate)August 7, 2022
  • Set permissions for a SharePoint list or library with Power AutomateAugust 3, 2022
  • Handle deleted files in synchronised SP library in Power AutomateJuly 31, 2022
  • Create item with lookup column in a dynamic list (Power Automate)July 27, 2022
  • How to move list between SharePoint tenants with Power AutomateJuly 24, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme