Cancel Flow Run instead of Terminate in the middle of an apply to each in Power Automate
Have you tried using terminate in the middle of an apply to each? Did you get The operation terminate cannot be used inside a for each?
Terminate
The terminate action is so often misused. As I mentioned a while back the terminate action should really not be used. But if you are inside an apply to each processing 1000s of records then cancelling out might be something that you want to do.
Cancel flow runs
There is now an option to cancel a flow run. As shown in the following example, I want to terminate my flow when the value of the item being processes is set to 4.
Using the Cancel Flow Run action you can now cancel your flow runs.
Yes, you could use this to cancel other flows( e.g. get a parent flow to cancel a child flow. Or the other way around. But you can also use this to cancel the current flow run.
Configure the cancel Flow Run action
To cancel the current run all we have to do is configure the actions as shown below:
For the Environment we can use:
workflow().tags.environmentName
For the Flow can use:
workflow().name
For the Environment we can use:
workflow().run.name
So just with a few simple expressions, we can cancel the current flow run, even inside an apply to each or do until step.
Continue Reading Pieter Veenstra’s Article on their blog
Cancel Flow Run instead of Terminate in the middle of an apply to each in Power Automate
Have you tried using terminate in the middle of an apply to each? Did you get The operation terminate cannot be used inside a for each? The terminate action is so often misused. As I mentioned a while back the terminate action should really not be used.
Blog Syndicated with Pieter Veenstra’s Permission
More About This Author
Array
- Modern Workplace26 March 2024Receive the available storage within your SharePoint Online tenant
- Modern Workplace20 March 2024Options for Documenting Your Power Apps: Comments, Code, and Controls
- Modern Workplace18 March 20242 ways to duplicate SharePoint Lists to support your Power Apps
- Modern Workplace14 March 2024Update a Hyperlink Column in SharePoint with Power Automate