Power Automate “Scope” action – what does it have to do with the error handling?

By | November 21, 2020

There is a strange action in Power Automate which is really not there to do anything other than to help you organize the Flow a little better, it seems:

image

We can use scopes to put other actions in them, so we can, then collapse and expand those scopes this improving the manageability of the Flow:

image

Is that all there is to it?

Actually, there is more, since there is also a function in Flows which can return inputs and outputs of all the actions which are inside a scoped action:

https://docs.microsoft.com/en-us/azure/logic-apps/workflow-definition-language-functions-reference#result

image

So, what’s the big deal?

See, it can really help with the error handling. How often would you see an error like this and you wouldn’t know exactly what has happened there?

image

The reason is obvious in this example – I used incorrect syntax for the Filter. However, what if the Flow becomes much longer and what if I did not know that there is an intentional error in the flow? With the error message above, I might not be able to say a lot about what was the cause of the error.

This is where “result” function comes in.

It’s an interesting function to start with, since it does not show up in the list of available functions (that’s what we call a “hidden gem”Smile )

I can use it:

image

But there are no hints or “intellisense”:

image

That does not make it less useful, though, since I can set the Flow like this:

image

Where my “Set Variable” action would run only if “Scope 1” fails:

image

With the actions configured as per the screenshots above, here is what will be store in the error variable:

image

Looking at the output of that “Set Variable” action, I can now see a lot more detailed error message:

image

And this has all become possible since there was

  • A scope action
  • A “result” function that can be used with the scoped actions

 

Those scopes look much more useful now, it seems!

PS. To those who have been working with Power Automate for at least a few years, this may have been known for a while – there is a great post on this topic here:

https://sharepains.com/2018/02/07/power-automate-try-catch-finally-flow/

Leave a Reply

Your email address will not be published. Required fields are marked *