Create and Call Nested Logic Apps
    • Dark
      Light
    • PDF

    Create and Call Nested Logic Apps

    • Dark
      Light
    • PDF

    Article Summary

    #ServerlessTips - Azure Logic Apps
    Author: Kent Weare Integration MVP

    When writing code, developers want a way to modularize their code so that they can reuse it and call it from other classes and methods.

    The need to call reusable logic also exists within Logic Apps.

    Consider a scenario where you encounter an error within your logic app processing and you want to create an Incident Ticket within an IT Service Management (ITSM) tool like ServiceNow. You wouldn’t want to repeat this same ServiceNow logic in every logic app that you build. Instead, you can centralize this logic to connect to ServiceNow and simply call it from your other Logic Apps.
    In this post we are going to build a nested logic app and then demonstrate how we can call it from other logic apps.

    1-Architecture.png

    Nested Logic App

    Let’s first build out our nested (or shared) logic app. In this case, we will add an HTTP Request trigger and define some message body attributes including Logic App Name, Error Message and Category. We will use these values to populate a ServiceNow Incident Requests. We will then return the ServiceNow Incident Number to the calling logic app.

    2-child.png

    Parent Logic App

    We will now build out a logic app that will call our nested, or child, logic app. To keep things simple, we will add a Recurrence trigger and then add an HTTP action. This HTTP action we will get to fail, on purpose, by including a bad URL. Next, we will add the Call Azure Logic App action and choose the selected logic app that we want to call.

    3-LogicApps.png

    Since we included message parameters in our nested logic app HTTP trigger, we see parameters that we can pass. For the LogicAppName parameter, we will use an expression of: workflow().name which will pass along the display name of our logic app. The Workflow and Trigger name fields will be auto populated.

    4-configure.png

    Now, we only want to call our nested logic app when our HTTP action fails. As a result, we will Configure run after settings an ensure that has failed is selected.

    5-OnError.png

    If we run our (parent) logic app, we will discover that our HTTP action fails, as expected and our nested logic app is called.

    6-runhistory.png

    We know that our nested logic app succeeded as it returned a ServiceNow TicketNumber.

    7-ticketnumber.png

    In this post, we discussed how we can create nested logic apps that can be called from other logic apps.

    azure-functions

    This allows us to centralize common logic.

    In the event we need to change this logic, we can change it in one place instead of many places if we would have embedded it in other logic apps.


    Was this article helpful?