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/

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

  1. MICHAEL WAN

    Get an error when using result(‘Catch grant permission’) to set variable. Flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The action(s) ‘Catch grant permission’ referenced by ‘inputs’ in action ‘Set_variable’ are not defined in the template.’.’.

    ‘Catch grant permission’ is the scope name.

    Reply
  2. MICHAEL WAN

    flow save failed with code ‘InvalidTemplate’ and message ‘The template validation failed: ‘The action(s) ‘Catch grant permission’ referenced by ‘inputs’ in action ‘Set_variable’ are not defined in the template.’.’.

    Reply

Leave a Reply

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