Showing posts with label Child Flow. Show all posts
Showing posts with label Child Flow. Show all posts

May 12, 2020

How to Call a Child flow from the Parent flow – Part Two

Introduction
In this article, we will see how we can create a Child Flow which is triggered from the Parent Flow. In the earlier blog, we discussed the business requirements and created a Parent Flow.

Now, let’s create a child flow in the same solution where we have created our Parent Flow.

Step 1: Add HTTP Trigger Action. From action select, "When a HTTP request is received".

We need to add Request Body JSON. Click on Generate from sample showing in the above screenshot. This will open below modal. We need to add sample JSON data to generate JSON Body. Add below JSON and click Done.

 {"Name" : "XYZ", "Experience" : 1, "Salary" : 20000, "Pay Scale" : 0.02, "ID" : 1 }  


So, here we need Name, Experience, Salary, Pay Scale and ID columns from Parent flow.

Step 2: Now, we need to multiply Salary with the Pay Scale. Add Compose Action and write logic to multiply Salary and with Pay Scale.

 mul(triggerBody()?['Salary'], triggerBody()?['Pay Scale'])  


Step 3: Now, add an action to update the item. Here in the Pay Scale Result field, we are passing the output of compose action method.
We also need to make sure that Is Trigger value is set to "No" otherwise the parent flow will continue running in infinity.

Step 4: After Update item action add “Respond to a PowerApp or Flow” action. Add this action to parallel branch.

In Success Action (left side action in above step), click ellipses and click "Configure run after" as shown in below screenshot.

Select "is successful" checkbox and click on done.

Same way, let’s configure the failure action. In Failure action set below options.

So, our child flow has been created successfully.

The above flow will return the variable to the Parent flow.

Conclusion: This is how, we can trigger child flow from the parent flow.

If you have any questions you can reach out our SharePoint Consulting team here.

May 4, 2020

How to Call a Child flow from the Parent flow – Part One

Introduction
In this blog, we will learn, how we can trigger a child flow from parent flow and send the response back to parent flow using Microsoft Power Automate. Sometimes, there are situations when we need to call child flow from parent flow to reduce repetitive flow actions.

We have divided this article in two parts.
 - Part One – Create a Flow solution and Parent flow.
 - Part Two – Create a Child Flow.

Lets have a look at real-life Use Case:
We have two different lists created in SharePoint Online.
1. All Employee Info List: This list holds all employee information.
2. Pay Rate List: This list holds experience and the pay scale information.

Now, as an end result, we need to calculate the total pay scale based on experience and salary and store the value to SharePoint list. We wish to reuse this calculation in multiple flows.

Overall Architecture/Schema of Lists:
Below is the column structure of the All Employee Info List.

And below is the column structure of the Pay Rate List.

Below is a sample data to calculate Pay Scale Amount.

So, now let's get started. As a first step to implement this Parent-Child flow, we need to create a solution in Flow first.

Create a Solution in Power Automate/MS Flow:
Click on Solutions in the left navigation and click on New Solution. It will ask the following information to fill out.

Display Name = Any meaningful name for your solution.
Name = This will be generated automatically once you fill-in the Display name.
Publisher = Select CDS
Version = 1.0.0.0

Once the solution is created, create a flow inside that solution. So, now let’s see how to create a flow inside that solution.

Creating a Parent flow:
From the solution, click on New and select Flow.

This will redirect to you to the new flow creation screen. Below is the overall structure of the flow which we are going to create.

Now, let’s check each action in detail.

Step 1: Add a trigger – "When an item is created or modified".

Step 2: We have used a trigger, whenever an item is created or modified here and we are calling child flow to get calculated value and updating the item again so the flow will go in infinite condition. To overcome that we are maintaining the flag. If trigger value is "Yes" then it will continue running the process otherwise it will terminate the current flow.

Step 3: Now, let’s get data from other SharePoint list and based on experience, get the value of Pay rate.


Step 4: In this action select child flow name and pass parameter to use in child flow. Here, we need to create a child flow separately in the same solution. Please go through "Create Child Flow Article" blog for the steps to create a child flow separately. Once you create a child flow, add an action – "Run a child flow".

This will ask for the following parameters which we have defined for our child flow.

Step 5: Set compose action to get the response from a child flow.

So, our parent flow has been created successfully, let’s verify the result.

Add a new item to the All Employee Info SharePoint list. This will add Pay Scale Result from child flow and update the value.


Conclusion:
This is how, we can create a Parent flow and call a child flow with the help of "Run a Child Flow" action in Power Automate.

If you have any questions you can reach out our SharePoint Consulting team here.