Microsoft Flow Series – Flows Calling Flows

 MS Flow, also known as Power Automate, allows you to create and automate tasks via numerous applications and services swiftly and easily. In MS Flow, these automated workflows are referred to as ‘Flows’ and it intuitively integrates a variety of Microsoft services and apps (Dynamics 365, Office 365, Power BI etc.).

Flow Building Blocks

When building Flows one of the approaches to simplify their structure, help troubleshooting and create re-usable modules is to make the Flows call other Flows. Natively, Microsoft Flows does not have a way for a Flow to call another Flow. However, Flows can be triggered on an HTTP request and they can also make HTTP calls, hence they can call each other by combining an HTTP request receive trigger and an HTTP request action.

Child Flow

We are building some Flows to help around our organizational structure. Create a new Flow, search for HTTP triggers to add, and there will be a one called “When an HTTP request is received”:

We can start building a new child Flow, which will do one thing. In this case, what we would like to do is for any user in our organization to return their direct reports if they have any.

We create the HTTP trigger (1), which has the option of being a POST or a GET method (2). In this case, we are using the GET method as we want this to be as universally available outside of Flow, even for systems which are not able to submit a POST call. Once this call is received this child Flow carries on with some other actions (3).

The first variable we initialize called “Manager” will be to store the manager username we receive from the GET attribute “manager” (1). The second variable “DirectReportsJSON” (2) we need to store the results as a JSON string. The Office 365 action “Get direct reports (V2)” is used in the “GetDirectReports” step (3) to query for the manager user in Office 365, fetch the direct reports, and pass them onto the loop (4). In the loop we iterate through the direct reports and compose the “DirectReportsJSON” contents. Finally, the “ReturnDirectReportsJSON” step (5) takes the variable “DirectReportsJSON” contents (6) and returns out of the Flow with a success code 200.

Parent Flow

In another Flow which will be the parent, we want to invoke this child Flow. This parent Flow we will use for fetching all user details from Office 365, including their direct reports information which will be provided by the other Flow we just created.

  • Add an HTTP request action which will make a GET method call to our other Flow (1).
  • Use the URI provided by the trigger in the other Flow and move the attributes to the queries section (2), include also the “manager” attribute to search for.

Calling Parent Flow

If we now test by calling the URI of the parent Flow, and passing it a manager attribute we can see the combined results in a single JSON:

  • The manager section provided by the parent Flow (1)
  • The direct reports appended to the manager from the child Flow (2)

We now have the option of calling for a combined action to return manager details and the direct reports, or reuse the child Flow in other operations when we just want the direct reports.

Stay tuned for more MS Flow content. People are always looking for the most intuitive way to increase automation for their workflows. Mastering MS Flow helps you achieve this, in addition to improving development efficiency.

Expand your knowledge of the Microsoft Modern Workplace, by subrscribing to our YouTube channel: