Introduction:
In this Part, we’ll show the process of integrating the child flow created in Part 1 into a Parent flow – the critical flow that you will be tracked for its history.
“If you missed Part 1, be sure to check it out for a complete guide on creating child flow in Power Automate.”
Step-by-Step Guide:
Integrate child flow to your Parent Flow:
Will continue with the remaining steps to incorporate the child flow and fully track the history of each run.
Step 1: Open Your Parent Flow and Add Essential Variables
To begin, open the existing flow you want to track. In this example, we’ll use an approval flow as the base for the parent flow.
Add the Following Variables:
- Start Time Variable:
To track the start time of the flow, create a variable called Start Time. Set its value to the current time using the utcNow() function.- This will capture the moment when the parent flow begins executing. It’s useful for tracking the duration of the flow later, especially when monitoring child flows.
- This will capture the moment when the parent flow begins executing. It’s useful for tracking the duration of the flow later, especially when monitoring child flows.
- End Time Variable:
- Similarly, create a new variable called End Time. You will set this later to capture the moment when the parent flow finishes. This will help you calculate the total runtime of the flow, including any child flows.
- Similarly, create a new variable called End Time. You will set this later to capture the moment when the parent flow finishes. This will help you calculate the total runtime of the flow, including any child flows.
- Workflow Status Variable:
Add another variable called Workflow Status. Initialize this with a default value of “Success”- This will track the overall status of the flow.
- This will track the overall status of the flow.
Step 2: Put Your Parent Flow Actions Inside the Scope Block
Once you’ve set up your variables, the next step is to organize your parent flow’s actions within a Scope block.
A Scope in Power Automate allows you to group multiple actions together. This makes your flow more organized and provides a clear structure for managing the flow’s execution. In this example, we’re putting all the parent flow actions inside the Scope block to track its execution clearly.
Steps to Implement:
- Add a Scope Action:
Search for and add a Scope action to your parent flow. This will act as a container for the actions that you want to track. - Include Flow Actions Inside the Scope:
Drag and drop all the necessary actions (like sending approvals, updates, or other tasks) inside the Scope action.- This will help maintain a clean and structured flow, making it easier to manage and track.
- This will help maintain a clean and structured flow, making it easier to manage and track.
Step 3: Create 3 Parallel Branches for Error Handling and Workflow Control
Now, we’ll introduce parallel branches to handle errors, timeouts, and other potential issues within the flow. This will give you greater control over the flow execution, especially when it involves critical operations like approvals.
- Add the First Parallel Branch:
- Click the “+” sign after the Scope action to add a Parallel Branch.
- In this branch, add the “Set Variable” action to change the Workflow Status to “Failed”. This will help capture and track if the flow encounters any failure.
- Action to Add:
- Set Workflow Status Variable to Failed.
- Set Workflow Status Variable to Failed.
- Configure the Run After Settings for the Set Variable Action:
- In this step, configure the Run After settings for the Set Variable action.
- Set the Run After condition to trigger if the Scope action fails or encounters an error. This will ensure that the Workflow Status is updated to “Failed” if any issues occur within the Scope.
- Example Configuration:
- Run After: Select has failed.
- Run After: Select has failed.
- Repeat the Previous Step for Timeout Handling:
- In the second parallel branch, add another Set Variable action to update the Workflow Status to “Failed” in case of a timeout.
- Set the Run After condition for this action to trigger if the Scope action times out.
- Example Configuration:
- Run After: Select has timed out.
- Run After: Select has timed out.
- Add a Third Parallel Branch with a Dummy Flag:
- Create another Parallel Branch, this time adding a Compose action.
- Use this Compose action to set a dummy flag or placeholder. This flag can be useful for tracking or debugging the flow.
- Action to Add:
- Compose: Use a simple string like “Dummy Flag” to ensure this branch runs successfully.
- Example Configuration:
- Run After: Select has Successful and Skipped.
- Run After: Select has Successful and Skipped.
Step 4: Add a Scope Block Next to the Dummy Flag Compose Action
In this step, we will add a new Scope block next to the dummy flag compose action to ensure that the workflow history is captured and tracked.
- Add a Scope Action:
- Add a new Scope action next to the dummy flag Compose action.
- Add a new Scope action next to the dummy flag Compose action.
- Configure Run After Settings:
- Set the Run After configuration for the new Scope action to trigger after the Compose (dummy flag) action completes. This ensures the scope runs after the previous actions have completed.
- Set the Run After configuration for the new Scope action to trigger after the Compose (dummy flag) action completes. This ensures the scope runs after the previous actions have completed.
- Add Workflow History Block:
- Inside the newly added Scope, add a Compose action. Name this “Workflow History Block” and set its value to the expression workflow().
- The workflow() function will return the details of the flow execution, including its start and end times, status, and other key properties.
- Example Action:
- Compose: Set value to workflow().
- Compose: Set value to workflow().
Step 5: Add the Child Flow Inside the Scope
Now, we’ll add the Child Flow inside the Scope to ensure that the parent flow properly runs and tracks the results of the child flow.
- Add the Run a Child Flow Action:
- Search for and add the Run a Child Flow action inside the newly added Scope.
- After adding the Run a Child Flow action, select the child flow you want to include in the parent flow. Upon selection, it will automatically generate the configured inputs for the child flow.
- Map the Workflow History Block:
- In the Workflow obj input for the child flow, map the value to
string(outputs('Workflow_History_Block'))
. - This step will pass the workflow history from the parent flow to the child flow for tracking purposes.
- In the Workflow obj input for the child flow, map the value to
- Map Remaining Inputs:
- Map any remaining values to the child flow inputs from the dynamic content provided by the parent flow. This ensures that all necessary information is passed down to the child flow.
- Map any remaining values to the child flow inputs from the dynamic content provided by the parent flow. This ensures that all necessary information is passed down to the child flow.
Accessing Child Flow in Different Environments:
For Same Environment:
- If you want to use the child flow in a different solution within the same environment, simply follow the same steps as you would to “Integrate child flow to your Parent Flow”.
- You will be able to see the child flow name in the “Run a Child Flow Action”
For Different Environment:
- To use the child flow in a different environment, you can export the entire solution as a .zip file. This file can then be uploaded to another environment or shared directly via the Power Automate Platform.
- After importing the solution into the new environment, ensure the connections are properly configured.
- Once the connections are verified, you can follow the same steps to “Integrate child flow to your Parent Flow”, and the child flow name will appear in the “Run a Child Flow Action”
Conclusion:
By following these steps, you’ve successfully created a Flow in Power Automate that tracks the history of its execution, incorporates child flows, and manages error handling. This setup provides transparency and ensures that all flow statuses are logged into your SharePoint or Dataverse, whether they succeed or fail.
Source: Read MoreÂ