Using Result() Expression to get an Action’s Status
    • Dark
      Light
    • PDF

    Using Result() Expression to get an Action’s Status

    • Dark
      Light
    • PDF

    Article Summary

    I have been spending more time recently working on exception handling and logging. When you catch an error and want to log a failure, there isn’t a great way to get a lot of details about why your flow failed, or is there? There is a function called result() that allows us to pass in an action name and it will return the outcome of that particular action.

    As part of the input parameter required to pass into the expression, we need to include the name of the action. You certainly would not want to track the results on a per action basis, so it is good that we can pass in the name of a Scope action instead.

    To demonstrate how this works, let’s create a simple flow that includes 2 scopes. One will represent our ‘try’ logic and one that will represent our ‘catch’ logic. Naturally, our Scope-Catch action only run if our Scope-Try action has failed, skipped or has timed out.

    We will deliberately force an action to fail within our Scope-Try by providing a bad URI within our HTTP action. As part of our Scope-Catch we will include a Compose action where will embed our result expression. The specific expression that we will use is: result('Scope-Try')

    Note: You need to be careful when you include the action name as part of the parameter for the result expression. If you action includes spaces they will be replaced with ‘_’. For that reason, it is best to name your actions without spaces. You can include ‘-‘ to make them more readable. In addition, if you change the name of your action, you need to also update your expression as that will not be updated automatically.
    1-design(3)

    Testing

    Let’s now test our flow and we will see the following result. As you can see, we get detailed information in the error node that includes specific information about why it failed. We can subsequently take this information and send to relevant stakeholders using email or Microsoft Teams.
    2-Testing

    Conclusion

    While not well known, the result() expression provides us with a direct way to get the outcome of an action, including Scope actions. This becomes very useful when wanting to log detailed information to a centralized log repository.


    Was this article helpful?