Latest Posts

Handle Errors and exceptions in Azure Logic apps using scopes


We must have faced a lot of issues while programming and what we used to do is apply try catch finally block. The azure logic app also comes with features using which we can apply error handling on logic app actions. We might face some data issues or system downtime issues because of which the running logic app can fail. Error and exception handling tools in the Azure logic app help us to build robust applications.

Run after behavior without scope

  • In the logic app, we straight away declare the sequence of the action to be executed.
  • There is one setting in the logic app using which we can decide whether to execute it or not, based on the result of the earlier action.
Note:
  • In the designer, the "run after" setting doesn't apply to the action that immediately follows the trigger as the trigger must run successfully before the first action can run.
  • Run After setting applies to only two consecutive actions. You can not set Run after for action 2 or more than 2 steps above the action. It has to be exactly the earlier action.
  • Let’s go through a simple example. Open your logic app.
  • Put the trigger and actions in that logic app.
  • try catch block steps
  • Try Catch Finally….
    • Step #1: LastStep – We are executing a formula in this step. If this step fails, we are going to skip the next step (step#2: RunAfter), otherwise, we will go ahead and execute the step. Basically, this is our Try Block code.
    • Step #2: RunAfter – Here, we are going to set what result from the previous step (Step #1: Laststep) will execute or skip this step.
  • For Action Step #2: RunAfter, click on the ellipsis as shown in the screenshot and then click on Configure run after.
  • configure run after
  • You can expand the action and you will see four options there.
    • Is successful
    • Has timed out
    • Is skipped
    • Has failed
    • run after should run after
  • As you can see, I have selected two options, has timed out, and has failed.
  • So, if the previous step (one step above this one), results in any of these two then only this step will execute otherwise it will skip.
  • Run after behavior with scope

    • A big advantage/difference of using Scope is that you can use multiple actions (group multiple actions) for Try or Catch block.
    • After all the actions from the scope are completed running, then the scope itself gets its own status.
    • If all the actions in the scope are successful, then the scope status is succeeded. Even if one action failed, then the status is failed.
    • The process is the same, so we are not going to repeat it but for reference, you can see in the screenshot below those multiple actions are added.
    • run after behavior with scope

    Result() - Get Azure Logic app error details in the catch block

    • You can also get some details about the failed action in the Catch scope/block
    • The result() function can be used to get some information regarding the failure. The function takes only 1 argument which is the scope name (Try scope).
    • The result()function returns the results only from the top-level actions and not from deeper nested actions such as switch or condition actions.

    We value your Feedback:

    Page URL:

    Name:

    Email:


    Suggestion:

    © 2024 Code SharePoint