“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']
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!
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.