Power Automate: Implement Parent/Child Nested flows

Introduction

Calling a nested flow is one of common requirements in process automation. Previously there was no inherent action to call child flows and we had to make use of HTTP Request received action to simulate the Child Flows which involved manually construction of request and response messages using JSON

In this article we will see how to create a parent and child flow and how call invoke the child from the parent

Use Case

One of the use case is to the isolate the frequenetly used logic into a child flow so that it can be called from multiple other flows. It also helps in isolating the main logic out of the parent flow so that in case of any changes need to be done, we can do it in only one place. In addition to that it also prevents the flow from becoming large and monolithic.

In this article we will create a parent flow that gets triggerd when an item is created in a list called Department A. Within the flow we will call another Flow called Create a Copy that saves the item details into a Master List.The benefit of this approach is that if there is another list called Department B, if the same logic has to be replicated there to copy the record to master list, the flow running on Department B can easily call the Create a Copy flow to get the logic done.

Create the Child Flow

We will be creating the child flow within the Solutions tab. To create a new Solution, click on Solutions from the left navigation. Provide a Display Name, Name, Publisher and Version and click on Create.

Within the solution create a flow as shown below :

The child flow will use an HTTP Request Trigger  for invocation and we will also provide a JSON schema so that the parent flow that call the child flow knows the parameters that needs to be passed. We can use a sample JSON payload to indicate the incoming parametes.

{ “Title” : ”Department A March Sales”, “Total Sales” : “35000”, “Auditor” : “Priyaranjan” }

Add the above JSON to dialog box that opens up on clicking “Use Sample Payload to generate Schema”

On Clicking Done, it will generate the schema as shown below :

Now lets add the action to create the item in the master list using the data that was passed from the Parent Flow

Thus our Child Flow is completed.

Now as the last step, we have to include a response action else we will get the below error while creating the Parent Flow

So as to create the response action, add the step Respond to a PowerApp or flow and select the Text type of output

Click on the + Sign and insert a parallel branch with the same action so that one branch indicates success response and the other indicates a failure response.

Add Status as the Text field name in both branches and mention Success and Failure as the respective values for the Success and Failure Branches.

We now have to set the Configure after run section for each branch so that depending on the Outcome of the Item Update action, either one of these branches will be invoked. In order to do that lets first define the configure after run setting for the success branch.

Success branch will run only if the Create Item action Is successful as we have checked the Is successful check box.

Same way for the failure branch select all the remaining checkbox, so that if the Create Item action is not successful, the failure branch will run.

Create Parent Flow

Now lets create the parent flow in the same Solution that we have created. We will be using when an item is created as the trigger and will also add the Run a Child Flow action to the flow.

Select the recently created child flow from the drop down so that it gets called from within the parent flow.

On selecting the flow, it provides us with more option to add the parameters that will be passed to the Child Flow.

Save the parent flow.

Test the implementation

Now lets test the Parent – Child Flow invocation by creating a record in the Department A list and fill in the values for Title, Total Sales and Auditor. Ideally on creation, it would call the child flow and create the same record in the Master List.

Lets head over to the Parent list to see the flow run and we can see that it has successfully called the child flow :

Same way , the child flow has also run successfully.

We can also see that the new record has been created in the Master List through the Parent-Child Flow communication.

Summary

Thus we saw how to set up a Parent – Child flow and invoke them to automate the business process in SharePoint Online