The ability to call nested Logic Apps directly from Logic Apps Designer

Microsoft Integration Product team announced this month on their monthly webcast (that you can see it here) some of the new features that are now available in Logic Apps like:

  • “Run” any trigger now
  • HTTP Webhook in Designer
  • SQL Azure Connector now supports Store Procedures
  • Azure Functions Integration and a few other features

In my last blog posts I talked about the new “Azure Functions Integration” (here and here). One of the features that they announced that it would soon be available was “Call nested workflow in Designer”, and the good news is that it is now available to us “to play”.

This is a great feature that will allow us to:

  • Create reusable pieces
  • Overcome some Logic Apps limitations, and what I mean by that is for example:
    • The ability to add more than one action inside the condition branch’s (this is actually a false statement);
    • or the ability to add more than one action inside the loop;

Call nested workflows, or Logic Apps, from another Logic App, is actually not a new feature. We could previously achieve this as you can see in this post: Using Nested Azure Logic Apps … or Invoking Flows from another Logic App. However, it was not a “first-class” experience and we were forced to implement some workarounds to be able to achieve this goal…. Not anymore! Now it way more simple and with good user experience in the designer!

#1 Azure Monitoring Platform

Creating the child Logic App

The first thing that you need to know is that, if you want to create a Logic App that you can call through another Logic App:

  • The trigger of that Logic App needs to be “Manual – When an HTTP request is received
  • And it should finish with a “Response” action

If we don’t add the “Response” action in our child Logic App what will happen is:

  • The parent will call the child workflow
  • The child workflow will be executed
  • But the parent workflow will fail with the following error:

To wait on nested workflow ‘{Child Logic App Name}’, it must contain a response action.

Logic Apps father workflow fails without child response

Let’s create a simple scenario to demonstrate how we can call nested Logic Apps directly from Logic Apps Designer. In this sample, we want to create a child Logic App that:

  • It’s trigger manually, which means through an HTTP post;
    • In this case, let’s consider the following JSON message
{
   "Request": {
      "text": "text that we want to put in file content"
   }
}
  • Then it will call an Azure Function to dynamically generate a filename;
  • Create a Dropbox file
    • The filename it’s provided by the Azure Function;
    • And the content of the message it’s passed in the HTTP request that triggers this Logic App.
  • And finally return an HTTP response based on the status of the file creation;

To accomplish that we need:

  • On the Azure Portal click on “Logic Apps” option and click “Add” to create a new Logic App.
  • In the “Create logic app” panel we need to give it:
    • A “Name”, for example “AddFileToDropbox
    • Select the desired “Subscription” (if you have more than one)
    • Select the desired “Resource Group” or create a new one
    • And finally, define the “App Service Plan” by choosing an existing plan or add a new one
  • Click “Create” for the deployment process to start.

We have to wait a few seconds for the deployment process to finish, once it’s finished we will be notified in the notification area. You can check for more Logic Apps to create process details here.

If we select, from the Logic Apps list, the Logic App created above to open de Logic Apps Designer, we then need to:

  • From “Show Microsoft management APIs” option search box, click on the “Manual – When an HTTP request is received” trigger
Logic Apps Add Manual HTTP Request Trigger
  • Now, we need to give to the HTTP trigger the JSON message schema that will be sent, so that we can easily create steps.
    • Unfortunately, for now, is still not possible to configure the schema directly from the designer
Logic Apps Manual HTTP Request Cannot add schema
  • While Product team is improving this feature, for now, we need to switch to “Code view” and configure the schema on the “triggers” –> “manual” –> “inputs” –> “schema” property, that for now, it’s an empty schema
Logic Apps Manual HTTP Request set schema code view
  • To generate the JSON schema we can use the JSONSchema.net online tool to easily do that task for us.
  • We just need to past our JSON message sample provide above and click “Generate Schema
Logic Apps JSON Schema Generator
  • We then need to copy the JSON Schema from the website and paste it to on our Logic App code view schema property
Logic Apps Manual HTTP Request set schema code view fixed
  • Now that we have set our trigger, let’s move to the next step of our Logic App.
  • Select the plus sign, and then choose “Add an action
plus action
  • When you select “Add an Action”, again the search box will be presented where all the connectors with their available actions are listed. But now, on the search box, you can select the option: “Show Azure Functions in my subscription
Logic Apps Add Action Azure Function
  • From the search box select “Show Azure Functions in my subscription” let’s select (if you already have it) or create a new WebHook Node function call: “CreateFileName
module.exports = function (context, data) {    
        
  var Tweet = data.Tweet;    
  var d = new Date().getTime();    
  var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {    
        var r = (d + Math.random()*16)%16 | 0;    
        d = Math.floor(d/16);    
        return (c=='x' ? r : (r&0x3|0x8)).toString(16);    
  });    
        
  // Response of the function to be used later.    
  context.res = {       
    body: {    
      FileName: 'NewTweet_' + uuid + ".txt"    
    }            
  };
  • This function doesn’t need any input, so, we will set the “Input payload object” as an empty JSON message:
{}
Logic Apps Call Azure Function CreateFileName
  • Once again, select the plus sign, and then choose “Add an action
  • From the search box, type “Dropbox” and select the “Dropbox – Create file” action
Logic Apps Add action Dropbox Create file
  • Set the Folder path, let’s say the root by typing: /
    • Note: That you can also use the “…” button to navigate to your Dropbox folders
  • Click on the Filename and set the parameter “Body” from the output of “CreateFileName” function as input
    • You don’t need to do this step, but the reason why I do it’s because I am a little lazy and I want the designer to do half of the work for me
  • And then click on “File content” text box, and set the parameter “Text” from the output of “When an HTTP request is received” as input
Logic Apps Add action Dropbox Create file configured
  • On the top of the Logic Apps Designer click in “Code view” option, for us to fix the “File Name” input parameter
  • Then we need to edit Create file inputs to have the expected values
    • Change the “inputs” –> “queries” –> “name” property to:
@{body('CreateFileName')['FileName']}
Logic Apps Add action Dropbox Create file configured fixed
  • Now if we change to the Logic Apps Designer, by clicking “Designer” option, we will notice that the designer already renders this property and set the expected parameter.
  • Once again, select the plus sign, and then choose “Add an action
  • From the search box, type “Response” and select the “Response” action
    • Set the “Status Code” with the value “200
    • And set the “Body” as “The file created was ” and the filename parameter from the output of “CreateFileName” function as input
Logic Apps Add Response
  • Save your Logic App and we are now ready to use/call this workflow from other Logic Apps.
#1 Azure Monitoring Platform

Creating the parent Logic App

If we now create another Logic App – the parent – let’s call it “CallNestedLogicAppDemo”.

  • Add a “Twitter – When a new tweet appears” trigger, to look for a new tweet containing the hashtag “#LogicApps
  • Select the plus sign, and then choose “Add an action
  • When you select “Add an Action”, the search box will be presented where all the available actions. But now, on the search box, you can select the option: “Show Logic Apps in the same region
Logic Apps Show Logic Apps in the same region
  • This will show you all the available Logic Apps that you can call from your current Logic App
Logic Apps Show Logic Apps in the same region list
  • Let’s select the “AddFileToDropbox” that we create earlier
Logic Apps Show AddFileToDropbox

How cool is that! Yeh!

  • Don’t change the “Trigger name” this should be set to: “Manual”
    • Why? Because this is the default trigger type from your previous child Logic App.
  • And the “Text” property we need to set the parameter “Tweet text” from the output of “When a new tweet appears
Logic Apps Show AddFileToDropbox configured

Once again, “Save” your logic app and wait to a tweet to appear, we will see that a new file was added in your Dropbox:

Logic Apps Show file being added to dropbox

You can also check the runs of the Logic App to see if it runs successfully or if an error occurred and what, how long it took to run, inputs and outputs, among others

Logic Apps Show logic app runs

Unfortunately, here we don’t have similar functionality that we have on BizTalk Orchestration Debugger, the ability to “View Called orchestration”. It would be great to have here a similar one “View Called workflow runs”. I add this request on User’s voice and if you like it you can go there and vote.

If you want to achieve this, you need to go to the child Logic app, see the execution runs and check if all steps are proper executed.

Logic Apps Show child logic app runs

You now can reuse this “AddFileToDropbox” in several Logic Apps that you have or will create in the future.

The parent will always execute successfully because you always returning status 200 from your child Logic App!

Well, yes indeed my last step is returning a status 200 for the parent Logic App, but this will only happen if all previous steps of the flow will be executed successfully, otherwise an error status will be received.

To put this scenario to test, I changed the “Dropbox – Create file” action in my “AddFileToDropbox” Logic App to always create a file with the name “Demo1.txt”. I then waited to appear two different tweets. The result:

  • The first execution was executed successfully
  • And the subsequent executions failed
Logic Apps Show logic app runs failed

With the following error:

{    
    "statusCode": 502,    
    "headers": {},    
    "body": {    
        "error": {    
            "code": "NoResponse",    
            "message": "The server did not received a response from an upstream server. Request tracking id '08587405217965861441'."    
        }    
    }    
}

If we check the child execution, we will see that the Logic App is failing in the “Dropbox – File Create” action and the “Response” action will be aborted

Logic Apps Show child logic app runs failed
#1 Azure Monitoring Platform
Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

1 thought on “The ability to call nested Logic Apps directly from Logic Apps Designer”

  1. Great article Sandro!

    Is it possible to create the equivalent to a “SOAP HTTP manual trigger” based on a WSDL using Logic Apps (to replace BizTalk orchestrations exposed as SOAP Web Services)?

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top