5 Ways to Stop a Flow in Power Automate

Do you need to stop a flow in Power Automate?

There are many reasons why you might need to cancel a flow during its run. You may stop a flow if it’s taking too long to run, or perhaps it was triggered in error.

You might also want to build login into the flow that will terminate the flow based on certain conditions, or if a certain action fails.

Whatever the reason for ending your flow there are several ways to implement it. This post will show you how to stop a flow from running.

Stop a Flow from the Run History

The run history is where you will be able to see all the runs for your flow that have been completed or are currently running. It will also show the start time, duration, and status of the run.

For any runs that have the status of Running, you will be able to cancel the run.

Here’s how you can cancel a flow from the run history screen.

  1. Go to Cloud flows tab of My flows.
  2. Click on the Ellipses icon for the flow you want to stop.
  3. Select the Run history option from the menu.

You can also get to the Run history for a flow by clicking on the flow to get to the Details screen and then clicking on the All runs link in the 28-day run history section.

  1. Select the runs you want to stop.
  2. Click on the Cancel flow run(s) button that appears at the top when a run is selected.

A warning popup will display letting you know you are about to cancel the selected flow runs.

  1. Press the OK button.

This will stop the runs and no further actions in the run will execute and the status in the run history will update to show as Canceled.

Stop a Flow from the Run Progress

When you start a flow, you can see the progress of the flow as all the steps execute. This will show you which actions have been executed successfully, which have failed, which are currently running, and which are still yet to run.

When you test a flow from the flow builder, this progress screen will automatically show.

But when a flow is running in production, you can still see this progress screen for any of the runs.

This can be accessed from the Run history or Details screen by clicking on the start time of the run. This takes you to the progress screen for that run.

You can then stop the run by clicking on the Cancel button found in the top right of the progress screen.

Stop a Flow with a Condition

Selecting a run and manually canceling is not the only way to stop a flow.

It is possible to stop a flow based on some conditional logic in the flow.

You can use a Condition action to evaluate a test and stop the flow based on the results. If you leave the If no part of the condition empty, then the flow will stop running when the Condition results in the If no branch executing.

For this to stop the flow you will also need to make sure there are no other actions below the Condition. All the remaining conditions should be inside the If yes branch of the Condition action.

Stop a Flow with the Terminate Action

There is one way to make sure your flow stops regardless if your flow has further actions or not.

There is an action that is specifically meant to stop any other actions in your flow from executing.

The Terminate action will immediately end your flow run when it executes and no further actions in the flow will execute.

  1. Add the Terminate action to the point in your flow where you want to stop the run.
  2. Select the Status for your flow run to have when it is stopped by the Terminate action.

You can choose a status of Failed, Canceled, or Succeeded. This is the status that will appear in the flow run history if the flow is stopped from the Terminate action.

If you select the Failed option for the Status, you will also get inputs for an error Code and Message. These values will display in the out of the action and can help you debug what has happened in your flow.

Stop a Flow with the Power Automate Management Connector

Another way to end a flow with an action is by using the Cancel Flow Run action in the Power Automate Management connector.

In order to use this action, you will need to have the Run ID for the particular run you want to cancel. This is a unique identifier for each run instance of your flows and is only generated after the flow has been triggered.

You can find the Run ID in two places.

Run ID from the URL

You can find the Run ID in the URL of the flow run.

https://make.powerautomate.com/environments/Default-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/flows/YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY/runs/ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

Go to the flow Details screen and click on the Start time of the flow in the 28-day run history section. The URL in the browser address bar will look like the above.

  • X is the environment ID of the flow.
  • Y is the flow ID.
  • Z is the run ID.

Run ID from the WORKFLOW Function

You can also find the Run ID with the workflow function.

{
  "id": "/workflows/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
",
  "name": "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY",
  "type": "Microsoft.Logic/workflows",
  "location": "canadacentral",
  "tags": {
    "flowDisplayName": "Example Flow",
    "environmentName": "Default-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "logicAppName": "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY",
    "environmentFlowSuspensionReason": "Default:XXXXXXXX:XXXX:XXXX:XXXX:XXXXXXXXXXXX-None"
  },
  "run": {
    "id": "/workflows/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/runs/ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
    "name": "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ",
    "type": "Microsoft.Logic/workflows/runs"
  }
}

The workflow() expression will result in the above output where Z is the Run ID.

@{workflow()?['run']?['name']}

You can use the above expression to get only the name value from the workflow output object.

@{workflow()?['tags']?['environmentName']}

The above expression will get you the Environment ID.

@{workflow()?['name']}

The above expression will get you the Flow ID.

Stop a Flow with the Cancel Flow Run Action

The Cancel Flow Run action requires you to input three values.

  1. The Environment of the flow to cancel. This is actually the environment ID behind the scenes.
  2. The Flow name to cancel. This is actually the flow ID behind the scenes.
  3. The Run ID.

Unfortunately, there is no way to list all the Run IDs for a given flow in order to cancel all running instances of that flow with Power Automate.

There are three options for using the Cancel Flow Run action to stop a flow.

  1. Manually copy and paste the Run ID from the flow you want to stop. This isn’t very practical. It only allows you to cancel one flow and since you need to get the Run ID from the run history you might as well cancel the flow from there.
  2. Use the workflow function within a run to get the current Run ID and cancel the current run with the Cancel Flow Action. But in this case, you might as well use the Terminate action since it’s easier to set up.
  3. Use the workflow function to get the Run ID for each run of the flow and store it in a dedicated table to track the flow runs. You can then query this table to get all the Run IDs for flows that are running.

The most interesting option is to store all the Run IDs in a table to potentially later cancel them from Power Automate.

At a very high level, any flow you want to cancel using the Cancel Flow Run action should contain these steps.

  • The first step in the flow should use the workflow function to add a record to some data source. This record should include the Environment ID, Flow ID, and Run ID. It should also create a default status of Running.
  • The last step before the flow completes should update the record created so the status is either Failed, Cancelled, or Succeeded depending on the outcome of the run.

This will allow you to list all rows in the data source that have a status of Running, and then cancel them using the Run ID

Conclusions

Canceling a flow is a common task in Power Automate, especially during testing.

There are several methods for stopping flows. You can manually stop flows from the run progress screen or the run history screen.

It is also possible to stop a flow within a flow by using conditional logic, the terminate action, or using the Power Automate Management connector.

Which of these methods will you use next time you need to stop a flow? Let me know in the comments below!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

1 Comment

  1. Philip

    Had a non-reacting flow running for days. Built a small flow with input “Run ID” (from URL), worked like a charm. Thanks a lot!

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!