Learn about scopes in Power Automate, and how to create simple error handling
I had been working with Power Automate for about 3 months, when I was introduced to an action called scope.
Now I use scope for almost any flow that I create!
A scope as an action can’t really do anything, but still, it can do a lot of magic.
The scope action is functioning as a container, where you can insert your actions.
Here are 3 reasons view you should use scopes
1. Better overview of your flow
The picture below is simplified, but the idea is, that you insert actions inside a scope, and name that scope something more explainable.
This will give you a much better overview of your flow, and you can collapse the part of the flow that you are not working on.
When you load the flow, all scopes are collapsed by default, so you can quickly navigate to the part you want to work on.
2. Copy all actions inside a scope
If you need, lets say the same 5 actions in different parts of your flow, simply copy the entire scope instead of copying each action individually.
As pr. January 2024, this is not yet supported in the new designer, but can still be done in the old designer.
3. Error handling
There are many ways you can do error handling in your flows, but this is the most simple one.
Insert all your actions inside a scope (name it “main”).
Outside your scope, as you last action, insert an send an email action
In the settings of you send email action panel, unclick Is successful and select the other 3 options.
Setup the e-mail action with the subject “Power Automate xyz has failed”
In the body of your e-mail insert the below code as “dynamic content”, this will create a link for you directly to the flow that has failed.
concat('https://flow.microsoft.com/manage/environments/', workflow()?['tags']['environmentName'], '/flows/', workflow()?['name'], '/runs/', workflow()?['run']['name'])
I think it is important, that if you are using flows in a production environment, you get notified if anything stops the flow from running as expected.
Here is my entire flow
You will now get a notification if any of your production flows have failed. The next thing you could do it to write the error into a SharePoint list, so that the administrators can easely have an overview of failed flows