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 Canceled | The 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 Name | Column Type |
ProductName | default title column |
ProductQuantity | Number type |
Discount | Number type |
NeededDiscountsforBulkOrders | Yes/No type |
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)
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']
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']}
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
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
Our complete flow looks like the below:
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.
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.
In Outlook, the requested user will receive an email as below:
In the flow run history, we can see that the flow run status is canceled.
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.
Once the flow runs successfully, it notifies the requested user to deliver the product soon.
In Outlook, the requested user will receive an email as below:
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.
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'])
If yes, add a terminate control and choose the status as Cancelled as shown below:
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
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)
Our complete flow looks like the below:
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.
In the flow run history, we can see that the flow run status is canceled.
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.
Once the flow successfully runs like the below:
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.
In the flow run history, we can see that the flow run status is Test succeeded.
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:
- How to Change Trigger in Power Automate
- How to Remove Quotes from String in Power Automate?
- Split a String between two characters using Power Automate
- Power Automate increment number in SharePoint list
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.