Image of organizing a flow using scopes in Power Automate.

Keep Your Flows Organized Using Scopes in Power Automate

Josh Logozar
Josh Logozar
April 22, 2021

Power Automate is a powerful automation platform, but it doesn't take long for complex flows to become large and unwieldy. Let's learn how to organize an unruly flow and handle errors like a pro using Power Automate Scopes.

Logo of Microsoft Teams
Logo of SharePoint
Logo of Microsoft 365
Logo of OneDrive for Business

Drive Your SharePoint from Vision to Launch

We take a deep dive into your organization to assess, plan, and execute the optimal SharePoint solution to serve your current and future needs.
Learn More

We have discussed many different ways of leveraging Power Automate flows for your everyday work life. Most of those flows have been very basic, with only a few steps in each of them. What happens when your flows become more complicated, and you want to be able to understand what each step is doing?

Our Senior Developer, Jon, joins us today to show us how to manage our flows, and  errors in Power Automate.

What are Scopes?

Scopes are a special kind of action in Power Automate that, unlike other actions, do not perform any actual work. What makes them so special is that they can contain other actions. Almost like a flow within a flow.

This unique trait opens the door to all kinds of interesting behavior in your flow. The two I want to highlight today are:

Organizing your Flow

When creating a complex flow, it doesn’t take long for the sheer number of actions to get out of hand. Rather than scrolling up and down to navigate your Flow (or even worse, side to side!), you can drag-and-drop actions into a scope then click the title to collapse it. The scope and all the actions within will roll up into a single step, hiding sections of the flow you’re not currently working on. This helps clean up your workspace and lets you focus on the actions you’re actively editing.

To make your flow easier to follow, I would also recommend giving the scope a name that describes the behavior of the actions inside. For example, you could name a scope containing several approval actions “Request approval from all stakeholders”.

Improving Error Handling

When designing a flow, a commonly overlooked scenario is what happens when things go wrong. If you weren’t already aware, Power Automate gives us the option to handle errors by running a different set of actions when an action fails by using the “Configure run after” menu. While this is perfect for a simple flow, in more complex flows there may be instances where we want to handle errors from multiple actions or errors from anywhere in the flow.

By placing actions in a scope, we can “catch” any errors that occur within. This is because errors that occur on an action within the scope propagate “up”, causing the scope to fail as well. If we configure a “Send an email” action to run if the scope fails, we now have a flow that notifies you if anything within the scope fails.

Note: If you have a background in programming, you can think of a scope as a function or a method. It’s a way of encapsulating related actions together into a single logical unit. If you don’t have a background in programming, fear not, it will make more sense after we walk through an example.

My Dogecoin Transaction Calculator

Here’s a flow I’ve been working on: it sums my Dogecoin earnings, subtracts my Dogecoin expenses then posts my balance to a Teams channel (much to everyone’s chagrin).

Image of an example flow in Power Automate.
A Dogecoin Transaction Calculator flow made in Power Automate.

This is not the most complex flow, but it still has a few distinct steps that are a natural fit for scopes. Namely:

  1. Get my Dogecoin earnings from a SharePoint list then sum them
  2. Get my Dogecoin expenses from a SharePoint list then sum them
  3. Calculate the total
  4. Post to Microsoft Teams

The last two steps are fairly simple, so we’ll leave those alone, but steps 1 and 2 could benefit from a scope. Let’s create a new scope for step 1.

Image of creating a new Scope in Power Automate.
Creating a new scope within a flow.
Image of creating a new Scope in Power Automate.
New scopes start off as blank.

Now, we drag and drop each action into the scope then rename the step (click on the menu "..." then "Rename") in a way that describes the behavior of the actions within. In this case, “Retrieve and sum Dogecoin earnings”.

Note: In a scope, actions are performed sequentially from top to bottom, just like the outer Flow. Be sure to drag-and-drop your actions in the same order they appear outside the scope.
Image of adding actions into a scope in Power Automate.
Remember to add your actions in the correct order.

We will repeat this process for Step 2 by dragging and dropping actions followed by renaming the scope. After collapsing our two newly created scopes (by clicking on the title bar of the scope), the resulting flow now looks like this:

Image of a flow containing scopes in Power Automate.
The updated Dogecoin Transaction Calculator flow with the 2 scopes added.

This wasn’t a particularly complex flow, but we’ve still reduced the number of actions visible without sacrificing readability. The benefit of this technique becomes even more apparent when editing larger, more complex flows.

Adding Error Handing to Our Dogecoin Calculator

Now that we’ve re-organized our flow it’s time to add some error handling. In its current state, any errors that occur will be recorded in your flow’s run history. You may receive the occasional email from Power Automate notifying you that a flow is failing but you won’t receive any real-time notifications. For some scenarios, that might not be necessary but for mission-critical flows it’s important to be aware of issues as soon as possible.

To start, we add another scope and drag all actions (other than variable initializers) into it.

Image of adding a scope in Power Automate.
Begin by creating a new scope within the flow.

Next, we’ll add the handler. In our case, this will be an email notification, but this could be anything that fits your organization’s needs; from posting a message in a Teams channel, to creating a new ticket with your support team.

Image of adding a handler to a flow in Power Automate.
Add an email notification handler to the flow.

Now we configure this notification to run if the scope fails, or if it times out by clicking the menu "..." and selecting “Configure run after” on the notification action (not the scope). This tells Power Automate to run the action after the previous one fails or times out. Do note, you can add a parallel branch to run actions if the scope succeeds as well.

Image of configuring an action to run after another in Power Automate.
We can tell Power Automate to run the new action after a previous action.
Image of configuring an action to run after another in Power Automate.
Specify the conditions when the action should run.

And finally, the flow has been re-organized for readability and notifies us instantly if something goes wrong. Note the dashed red arrow pointing to our new error notification, this is a nice visual cue that it only runs when the scope errors.

Image of a flow with an added error notification in Power Automate.
The flow now with an added action in case the scope fails to run correctly.

Organize Your Flow with Scopes

As you can see, Scopes are an amazing tool for keeping your flows organized and helping manage and mitigating errors. Thank you again, Jon, for writing this piece and letting users see the behind the scenes, and what we can do here at Blueshift.

This flow can be used for much more than just Jon telling us how much Dogecoin he has. You could use it for projects, making sure that you stay within budget, with just a few simple tweaks to your flow. If you have a business idea, contact us at Blueshift, and we can have people like Jon working with you to make your idea a reality.

Looks like you're using an older browser, so our website may not be displaying as intended. We recommend using a modern browser like Microsoft Edge to get the best experience!

  Blueshift Connects: Find out who will be receiving 80 hours of Microsoft 365 Consulting!