blog.atwork.at

news and know-how about microsoft, technology, cloud and more.

Handle failed actions in Azure Logic Apps

Today´s a quick tip for users working with Azure Logic Apps. This article shows how you can continue to work in a flow if an action has failed. This sample accesses an Excel file from a Microsoft teams SharePoint site and searches for a key. If the key was not found, the flow shall continue and deliver a useful error code with a message. See how this works here.

The scenario

The following Azure Logic App is triggered by an HTTP request and gets some data from another system. The purpose is to lookup a campaign and some data from an Excel file that is stored in a SharePoint site of a Microsoft 365 Group (a team site) and to continue to work with that data. Furthermore, the Logic App generate a voucher and sends emails. But that´s another story. Here we concentrate on the failure handling.

Here´s the beginning of the Logic App in the Azure portal designer. After the Logic App is fired, we lookup a campaign that was delivered in the JSON body of the HTTP request (see the Test it section below). If the campaign was found, we continue with our operations. The interesting part here is the reaction, if the campaign was NOT found in the Excel table.

image

Let´s see the details.

Access an external data source

We access the following Excel table stored in a team. We need to find the corresponding campaign and read the voucher numbers and some more details to find out what´s the next voucher number and how many vouchers are still available to generate a new voucher or to deliver an appropriate status later.

image

We get the data with the Excel connector in the action "Get rows" and read data from Table2 as here. Note: The data MUST be formatted as an Excel table. We rename the action to "GetCampaign". As Key Column, we search for column A, Campaign. As Key Value, we pass the data "campaignid" @{triggerBody()?['campaignId']} from the HTTP request as filter.

image

React to the result with Configure run after

If no row (campaign) was found, the flow would break. So, we need to modify that behavior. We can change that in the IF condition after the GetCampaign action in the settings of the action by clicking on the "..." icon and "Configure run after".

image

Here, we can continue even if the previous action failed. So, we switch the "has failed" option to ON, as here.

image

Ok. So the flow does not break. If we call the Logic App with a non existing campaign, the GetCampaign returns such a 404 result:

image

React with an IF condition

Let´s continue. The condition shall check if the previous action returned with such an HTTP status 404 (not found) error. I needed to do some research to find the correct expression, so here it is:

actions('GetCampaign').outputs.statusCode

We can add that code as expression in the dynamic data popup. We need the result of the action GetCampaign and the resulting .outputs.statusCode.

image

So our condition is as follows: @actions('GetCampaign').outputs.statusCode equals 404

image

Sounds logical, or? Of course, we could also react to status code 200 (ok) and react to all other codes and generate an error. Adapt it as needed.

React and terminate or continue

At the end, wen want to inform the caller in that case that the operation needs to be aborted. If the action was 404, not found, we send an error code and terminate the app. Otherwise, the Logic App shall continue to do what it´s supposed to do. This happens with the actions after the condition.

image

The Terminate action is important to exit here, if we don´t add all the actions in the False tree.

Test it

To test the Logic App, Postman helps. We send a non-existing campaignid to the Logic App.

image

As result, we get the desired information. The campaign was not found in the Excel file. This works well.

Summary

This sample shows how to work with failed actions in Azure Logic Apps. "Configure run after" is the key to include failed actions. Then, you can access the action result - depending on the action - with @actions('GetCampaign').outputs.statusCode and query the result and continue or break here. The Terminate action is helpful, if your want to end the workflow.

I hope this quick tip helps for your workflows!

Comments (2) -

  • Markus Hanisch

    10/7/2020 6:03:22 AM |

    Thank you for sharing, Toni.
    I assume that your solution will also apply in a similar way in Power Automate.

  • Toni Pohl

    11/2/2020 7:49:54 AM |

    Hi Markus, sure.
    Just, for HTTP operations, the user must have access to the premium connectors.

Loading