Subflows essentially break down a larger, more complicated process into smaller, more manageable parts. In the context of Power Automate, they enable us to modularize your workflows for reusability and organization. By creating subflows, you can reuse a set of actions across multiple flows.
Creating Subflows
To create a subflow in Desktop Flows, follow the steps below:
- Open the main flow where you want to add the subflow.
- Go to the ‘New step’ button and click on ‘Add an action’.
- Search for ‘Run a child flow’ in the actions list.
- Select the subflow you want to link to the main flow from the drop-down list.
Passing Parameters Between Main Flows and Subflows
You can also pass parameters (information) from a main flow to a subflow and vice versa. These parameters can be anything from strings, numbers to objects and arrays. Now, let’s see how we can pass a parameter from the main flow to the subflow.
In the main flow, in the ‘Run a child flow’ action add a new input. This input will be the data you want to pass to the subflow. Write the necessary expression or value that will serve as the input for the child flow.
To use this parameter in the subflow:
- Go to the subflow.
- In the trigger point of the subflow (where the flow starts), go to ‘Add an input’
- Create a new input with the same name as the one given in the main flow. Now when your main flow calls the subflow, it will pass the value to this input.
It’s important to make sure the names of the input parameters align. If the names in the main flow and subflow do not match, the parameter will not pass correctly.
Returning Values from Subflows to Main flows
Subflows can also be designed to return a value back to the main flow. This can be particularly useful if the subflow is executing a particular task, and the main flow needs to know the result of that task.
To send a value from the subflow back to the main flow:
- In the subflow, go to ‘Add an output’
- Write the necessary expression or value that needs to be returned.
- In the main flow, the ‘Run a child flow’ action will now have an output value from the subflow.
It should be noted that while we can have multiple input parameters from the main flow to the subflow, only one output is allowed from the subflow to the main flow.
Practical Use Cases
Subflows provide a great way to optimize your workflows and make them more efficient. Consider a scenario where you need to extract, process, and load data frequently. Instead of creating these actions repeatedly in multiple flows, you can create a subflow for each step and simply call them in the main flows. This not only makes your flow more readable and organized but also saves development time.
In conclusion, by implementing subflows in Desktop Flows, your Power Automate RPA development can become more organized, reusable, and efficient. With the ability to pass parameters and return values, they can be a powerful tool in your workflow design.
Practice Test
True or False: Subflows can be edited separately from the main desktop flow?
- True
- False
Answer: True
Explanation: Subflows can be managed independently of the main desktop flow, giving autonomy and flexibility to developers when modifying parts of an application.
What is a major benefit of implementing subflows in desktop flows?
- A) They can be reused across multiple desktop flows.
- B) They can be deleted once the main flow is completed.
- C) They require less memory to use.
- D) They only need to be programmed once.
Answer: A) They can be reused across multiple desktop flows.
Explanation: The key benefit of subflows is reusability. They can be used in other flows, reducing redundancy and facilitating smoother implementations.
True or False: A subflow cannot call another subflow in a desktop flow.
- True
- False
Answer: False
Explanation: A subflow can indeed call another subflow. Subflows can be nested within other subflows which allows creating complex automation processes.
What can be leveraged to reduce repetition and improve maintainability of your Power Automate RPA applications?
- A) Subflows
- B) Data sources
- C) Libraries
- D) Conditions
Answer: A) Subflows
Explanation: Subflows in Power Automate RPA enable reuse of flows functionality thus reducing repetition and improving maintainability.
When dealing with complex automations, it’s best to:
- A) Work on one long, continuous desktop flow.
- B) Break the automation down into several smaller desktop flows.
- C) Create one massive subflow.
- D) Ignore complexity and focus on basic features.
Answer: B) Break the automation down into several smaller desktop flows.
Explanation: Breaking the automation down into smaller, more manageable parts or subflows, helps to mitigate issues and improve maintainability.
True or False: Desktop flows only support Cloud flows as subflows.
- True
- False
Answer: False
Explanation: The desktop flows support not only Cloud flows but also any other desktop flow as a subflow.
When using a subflow, a developer can:
- A) Test the main flow without testing the subflow.
- B) Test the subflow without testing the main flow.
- C) Cannot test the main flow and subflow separately.
- D) Need to test all subflows together.
Answer: B) Test the subflow without testing the main flow.
Explanation: The independent nature of subflows allows for them to be tested separately from the main flow.
Subflows should be used to encapsulate:
- A) Tasks that are likely to change frequently.
- B) Easily understood tasks.
- C) Tasks that are used only once.
- D) All of the above.
Answer: A) Tasks that are likely to change frequently.
Explanation: Tasks that are more likely to change frequently are ideal candidates for subflows as they ensure easier maintainability and testing.
True or False: Parameters can be passed from the main flow to the subflow.
- True
- False
Answer: True
Explanation: Parameters can be passed to subflows from the main flow allowing smoother integration between the two.
Subflows in a desktop flow are executed:
- A) In parallel with the main flow.
- B) Before the main flow execution.
- C) After the main flow execution.
- D) In the context of the main flow.
Answer: D) In the context of the main flow.
Explanation: Subflows are sub-procedures or functions that operate within the larger, main flow. Consequently, they are executed in the context of this main flow.
True or False: Once a flow has been converted into a subflow, it cannot be converted back to a regular flow.
- True
- False
Answer: False
Explanation: Subflows can be converted back to regular flows – this process is not irreversible.
True or False: Subflow in Power Automate Desktop are stored separately from the parent flow.
- True
- False
Answer: True
Explanation: Though a subflow is created and called from within the parent flow, it is stored separately and can be independently managed.
Interview Questions
What are Subflows in Desktop Flows?
Subflows in Desktop flows are reusable components that can be used in multiple desktop flows. They allow for reusability and sharing of common work without redundant efforts.
How do we create a Subflow in Desktop Flow?
You can create a Subflow by selecting ‘New’ and then ‘Subflow’ from the main menu of Power Automate Desktop.
Can we use variables in Subflows?
Yes, you can define input and output parameters to pass and return values in Subflows.
How do you call a Subflow from the main flow?
You can navigate to the ‘Actions’ pane, expand the ‘Subflows’ category, and drag and drop the desired Subflow into the main flow.
What are the benefits of using Subflows in Power Automate Desktop?
Subflows reduce redundancy and increase maintainability by allowing developers to reuse components. By using Subflows, if there’s an update or change to a common process, it needs to be updated only in one place.
Can Subflows be nested?
Yes, Subflows can be nested. A Subflow can call another Subflow.
Is it possible to use controls like If, Loops, and Switch inside a Subflow?
Yes, controls like If, Loops, and Switch can be used inside a Subflow.
Can Subflows be shared amongst different Desktop Flows?
Yes, Subflows can be used across multiple Desktop Flows and can provide a single point of maintenance for commonly used workflows.
Are there any limitations to the number of Subflows that can be created in a Desktop Flow?
No, there are no specific limitations on the number of Subflows that can be created in a Desktop Flow.
Can we debug Subflows individually?
Yes, Subflows can be debugged individually.
Can variables be directly accessed between Main Flows and Subflows?
No, To access a variable in a Subflow, it must be passed as an input parameter.
Can we trigger a subflow directly?
No, a subflow cannot be triggered directly. It has to be called within a Main flow.
Can a Subflow return output to the Main Flow?
Yes, a Subflow can return output to the Main Flow using output parameters.
Is it possible to create subflow within a subflow?
Yes, a subflow can be created within a subflow, also known as nested subflows.
Can we use subflows in Power Automate cloud flows?
No, subflows are exclusive to Power Automate Desktop flows and cannot be used in Power Automate cloud flows.