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.
{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.
One small callout is the input has to have all the " replaced with ' (as else the regex will return null)
replace(string(result('Main')), '"', '''')
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
*This post is locked for comments