Power Community

Power Community

One Minute Fixes – Reading Exception Message

Reading the error message with the result() expression can be a challenge. Due to the response being a nested json, it is incredibly difficult to get the right error message. 

This is because the response returns all successful actions, all nested actions (e.g within scopes and conditions) and the fail propergates up (so if an action within a condition fails, the condition also fails). If you want to know more about the json check out this blog https://dev.to/wyattdave/exception-handling-in-power-automate-4c4h.

But there is a way to always get the error message, and that is to use custom code within a Dataverse Low-code plug in’s. These plug ins are actually Power FX powered api’s and are very cool. So we can use them to transform the response into just the error messages.

wyattdave_0-1715869124555.png

{ReturnMessage:
    Concat(
        Filter(
            Split(
                Substitute(Concat(MatchAll(ExceptionJSON,"essage'[^}]*'"),FullMatch&"|"),
                    "essage"
                ,
                    "'message"
                )
            ,
                "|"
            )
        ,
            !("is skipped" in Value) And !("No dependent actions succeeded" in Value)
        )
    ,
        Value
    ,
        "|"
    )
}

The code uses a regex to identify all messages (“essage” as some are Message, some are message). The list is then filtered to remove “is skipped” (as these are all of the actions that were after the exception) and “No dependent actions succeeded”, as this is the exception bubbling up to the container (scope, condition, apply to each, etc). All errors are then concatenated into a pipe delimited list.

The api is called in the flow by using a Dataverse Unbound action.

wyattdave_1-1715869905227.png

One small callout is the input has to have all the ” replaced with ‘ (as else the regex will return null)

replace(string(result('Main')), '"', '''')

wyattdave_2-1715870403615.png

The plug is attached to download.

>——————————————–
This is a series of short blogs designed to help find solutions for random problems before you ask, keep your eyes out for more

Fixing Redirect URLS
Fixing Cant Call a Flow from a App
Summing Up the Fields

Outlook Trigger Not Firing 

l also do long form and broader Power Platform blogs here https://dev.to/wyattdave

ExceptionMessagePlugin_1_0_0_0_managed.zip

This post was originally published on this site

- Advertisement -spot_img

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement - Advertisement

Latest News

Create Brand Profiles in Customer Insights – Journeys to Create Cohesive Brand Experiences

In this blog, we will learn about one of the new features introduced by Microsoft in Dynamics 365 in...

More Articles Like This

- Advertisement -spot_img