How to Stop Flow in Power Automate?

Do you want to stop a flow in Power Automate? The tutorial will help you understand stop flow by using the cancel flow run action and terminate control in Power Automate flow with different examples.

Scenario:

Recently, I received a requirement to check if the Product Quantity is greater than or equal to 10 and if the users need discounts for the selected product quantity.

If yes, then I have to cancel the current flow and notify the requested user to deliver the product within some period because the product discount is closed.

Similarly, If the Product Quantity is less than 10 and the Product Quantity is greater than 10 without any discounts, then it notifies the requested user to deliver the product soon.

Before that, we must know the difference between terminate control and cancel flow run action in Power Automate.

Difference Between Terminate control and cancel flow run action

Let us see the difference between terminate control and cancel flow run action in Power Automate

Terminate control Cancel flow run action
Terminate control stops the flow, and doesn’t perform further actions.The cancel flow run action doesn’t stop the flow and also it performs further actions.
Terminate control will terminate the whole flow. We cannot use it inside the for each control We can use the cancel flow action inside for each control
The status of the flow is CanceledThe status of the flow is Canceled

How to use Cancel flow run action in Power Automate

Let us see how to use the cancel flow run action in Power Automate flow,

Example-1:

In this example, I am going to use the below SharePoint Product list consisting of,

Column NameColumn Type
ProductNamedefault title column
ProductQuantityNumber type
Discount Number type
NeededDiscountsforBulkOrdersYes/No type
How to use Cancel flow run action in Power Automate

Follow the below steps to create a flow:

Step-1:

Create an automated cloud flow with a trigger when an item is created. Configure the required parameters.

  • Site Address: Select the SharePoint site from the dropdown.
  • List Name: From the dropdown, select the list name (here, I have selected the Product list)
How to use Cancel flow run action in Power Automate flow

Step-2:

Now add a condition control and check if the ProductQuantity is greater than 10 and NeededDiscountsforBulkOrders is equal to true.

@triggerOutputs()?['body/ProductQuantity']
@triggerOutputs()?['body/NeededDiscountsforBulkOrders']
Power Automate Stop Flow

If yes, add a Cancel Flow run action and configure the required parameters:

To get the Environment name, use the below expression:

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

To get the Flow name, use the below expression:

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

To get the Run ID, use the below expression:

@{workflow()?['run']?['name']}
How to end a flow in Power Automate using cancel run flow action

Add a new step, choose an send an email (V2) action, and pass the required parameters:

  • To – From the dynamic content, choose the Created by Email Address.
  • Subject – Provide the subject of the mail
  • Body – Enter the body of the mail
How to cancel running in Power Automate flow

If no, Add a new step, choose the send an email (V2) action, and pass the required parameters:

  • To – From the dynamic content, choose the Created by Email Address.
  • Subject – Provide the subject of the mail
  • Body – Enter the body of the mail
cancel running in Power Automate flow

Our complete flow looks like the below:

Cancel Flow Run in Power Automate

Step-3:

Save and run the flow by selecting the Run flow option:

TestCase -1:

Here, I have created the below highlighted SharePoint list item, where the Product Quantity is greater than 10, and NeededDiscountsforBulkOrders is Yes.

How to cancel running Power Automate flows with cancel run flow action

Once the flow runs successfully, it cancels the flow run and sends an email to the requested user to deliver the product within some period because the product discount is closed.

cancel running Power Automate flows with cancel run flow action

In Outlook, the requested user will receive an email as below:

Configure the cancel Flow Run action in Power Automate

In the flow run history, we can see that the flow run status is canceled.

Configure the cancel Flow Run action in Power Automate flow

Test Case-2:

Here, I have created the below highlighted SharePoint list item, where the Product Quantity is greater than 10, and NeededDiscountsforBulkOrders is No.

Cancel Flow Run Action in Power Automate

Once the flow runs successfully, it notifies the requested user to deliver the product soon.

Cancel Flow Run Action in Power Automate flow

In Outlook, the requested user will receive an email as below:

How to Cancel Power Automate Flow Run

This is how to use Power Automate flow’s cancel flow run action.

How to use Terminate control in Power Automate

Let us see how to use the Terminate control to stop the flow in Power Automate,

In this example, I will show you how to stop the flow by using terminate control whenever a certain person tries to create an event using flow.

Step-1:

Create an instant cloud flow, expand the trigger action, add a text input, and enter the name as the event subject.

How to use Terminate control in Power Automate

Step-2:

Add a condition control and check if the username is equal to a certain person; in my case, I have passed the user as Adele Vance.

So if the Particular user tries to create an event, then the flow uses terminate control to stop.

decodeBase64(triggerOutputs()['headers']['x-ms-user-name-encoded'])
How to use Terminate control in Power Automate flow

If yes, add a terminate control and choose the status as Cancelled as shown below:

Terminate control in Power Automate flow

Add a new step, choose the send an email (V2) action, and pass the required parameters:

  • To – From the dynamic content, choose the User Email Address.
  • Subject – Provide the subject of the mail
  • Body – Enter the body of the mail
Terminate control in Power Automate

If no, add a create event action from the action trigger and provide the required parameters:

  • Calendar id: From the dropdown, select the calendar id
  • Subject: Pass the dynamic content of the Event Subject
  • Start Time: 2023-11-10T08:00:00
  • End Time: 2023-11-10T10:00:00
  • Time Zone: (UTC-05:00) Eastern Time (US & Canada)
Exit a flow using Terminate in a Condition action in Power Automate

Our complete flow looks like the below:

Exit a flow using Terminate in a Condition action in Power Automate flow

Step-3:

save and run the flow by selecting the run flow option:

Test case -1:

I am going to trigger the flow with the user called Adele Vance, So the condition matches and goes to the if yes part, and the Terminate control runs and cancels the flow.

We can also see the Send an email(V2) action is skipped because the terminate control stops the flow and doesn’t perform further actions.

Exit a flow using Terminate control in Condition action in Power Automate

In the flow run history, we can see that the flow run status is canceled.

how to Stop a Flow with the Terminate Action in power automate

Test case -2:

Here, I have shared the flow with another test user called (Miriam Graham) with all connections.

I am going to test the flow with Miriam Graham user, Enter the Event Subject, and choose the Run flow action.

Stop a flow using Terminate control in Condition action in Power Automate

Once the flow successfully runs like the below:

Stop a flow using Terminate control in Condition action in Power Automate flow

In the Outlook calendar event calendar ID, we can see that the event gets created for the test user because the condition returns a false value.

Stop a Flow with the Terminate Action in power automate

In the flow run history, we can see that the flow run status is Test succeeded.

how to Stop a Flow with the Terminate Action in power automate flow

This is how to use the Terminate control to stop the flow in Power Automate.

Conclusion

So, I hope you get a stop flow by using the Cancel flow run action and Terminate control in Power Automate. Also, I have covered the difference between the Terminate control and Cancel flow run action in Power Automate.

In the first example, I have shown you how to work with the Cancel flow run action in Power Automate. In the second example, I have shown you how to use the terminate control in the Power Automate flow with an example.

You may like the following tutorials:

>