This blog gives information about creating or establishing a parent-child relation in Logic Apps in the designer. In simple words calling one logic app inside an another logic app.
Purpose of Nested Logic Apps:
The major advantage of this feature is to create reusable pieces:
- Archiving source file is a common process in all file processing applications.
- Decryption of the encrypted file or vice-versa
- Sending an alert mail on failure
Lets create TWO Logic Apps to demonstrate this and call them as
- PARENT Logic App – The Logic App that will call the another Logic App.
- CHILD Logic App – The Logic App that will be called from PARENT.
If you want to Invoke CHILD Logic App from another Logic App, it should start and end with below mentioned trigger and action respectively:
- The Child Logic App should have its Trigger to be “Manual – When a HTTP request is received”
- The Child Logic App must and should end with a “Response” action.
Creating Child Logic App:
- Login to Azure portal using your credentials.
- Navigate to your resource group using Resource groups option and then click on Add or Create resources.
- Type Logic Apps in the Marketplace search box and then click on Create.
- Provide all the required details like Name, Subscription, Resource Group, Location and then click on Create to start the deployment of Logic App.
- Now navigate to the Logic App Designer of ChildLogicApp and type for Request Trigger in the “Search Connectors and Triggers” search box.
- Here it trigger manually means that it will trigger through a HTTP post, which in turn means that we need to provide some request body. Let consider the below JSON message for the request.
- You can avail “Use Sample Payload to generate schema” option in the trigger to generate the JSON Schema for your JSON message automatically.
- Now complete the Logic App with necessary Actions for archival process as per your requirement. Here I am just making the CHILD Logic App to display the name of the SourceFileName that sent from PARENT Logic App for archiving and the final app will look like as the one shown below:
- **We will create a Response Action later in this Logic App, lets create a PARENT Logic App to call this CHILD by following the steps.
Creating PARENT Logic App:
- Use the similar steps to create PARENT Logic App as shown above and then to call the CHILD Logic we need to search for Logic Apps in the action search bar and select the option as shown below:
- When you select Choose a Logic Apps workflow option, it will list all the available Logic Apps (which has Manual Trigger) in the resource groups of your subscription. Select the appropriate one as shown below:
- After selecting the ChildLogicApp Logic App you can see the request which you provide in the CHILD Logic App’s JSON schema there in that action i.e SourceFileName.
- Here in the above snap, I am sending the text from PARENT Logic App that I want to assign it to a variable in the CHILD Logic App. Now run the Parent Logic app and see the run details.
- You can see the Parent Logic App successfully called the CHILD Logic App and then the CHILD Logic App assigned the value we passed from parent to the variable as expected.
- But if we see the PARENT Logic App Run Details (Image 09), even though the CHILD Logic App got succeeded (Image 10), the action in PARENT got failed with a error saying “To wait on nested workflow, child logic app will contain a Response action”.
- This is because the PARENT Logic App’s action where we called the CHILD logic app will expect the response from it for further processing, otherwise it will assume that CHILD got failed and it will fail the action.
- So we have to send a Response from the CHILD logic app saying that it got executed successfully. Now let go and create a Response action in the CHILD Logic App just by searching for response in the action’s search bar and it will looks like as shown below:
- You can provide the response body in JSON format by just clicking the add new parameter option. Save the Logic App and trigger the PARENT Logic App again and see the run details now.
For Your Information:
- The CHILD will always send the status code – 200 if all the previous actions will run successfully, if some action failed before the response, the status code will be different and it will fail the PARENT ChildLogicApp action.
- To test this scenario, I am manually pass a response code – 456 in the CHILD Logic App and triggered the PARENT and the run details will be as shown below:
- We can see that the PARENT Logic App got failed with the changed response in the CHILD Logic App.
I hope the blog was clear about creating Nested Logic Apps, please feel free to share your valuable feedback to improve this blog.
Thanks for reading…! Happy Learning…!