Subflows in Desktop Flows
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 10 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Lesson: Mastering Subflows in Desktop Flows
Introduction: The Power of Modularity in Automation
When you begin building desktop automations, it is common to start with a single, long list of actions. You record a few clicks, add some variables, and perhaps include a loop or two. However, as your automation requirements grow in complexity, this "linear" approach quickly becomes a liability. A single flow containing hundreds of actions is difficult to read, nearly impossible to debug, and fragile when changes are required. This is where the concept of the Subflow becomes essential.
A subflow is essentially a distinct, reusable block of actions that exists within the scope of your main flow. Think of it like a function in traditional programming. Instead of writing the same logic over and over or creating a massive, sprawling script, you break your automation down into logical, bite-sized components. By mastering subflows, you transform your automations from messy scripts into organized, maintainable systems that are easier to test and modify.
Understanding subflows is not just about keeping your workspace clean; it is about adopting a professional mindset toward automation development. When you use subflows effectively, you reduce the risk of errors, make your work accessible to other team members, and significantly cut down the time required to update your bots when the underlying applications change. In this lesson, we will explore everything you need to know about creating, managing, and optimizing subflows in your desktop automation projects.
Not read yet
Understanding the Architecture of Subflows
To effectively use subflows, you must first understand how they interact with the main flow. Every desktop automation project starts with a "Main" flow—this is the entry point that the automation engine executes first. A subflow is a secondary flow that is triggered by the Main flow. Once the subflow finishes its tasks, control is passed back to the Main flow at the exact point where it left off.
This relationship creates a hierarchical structure. You can imagine your automation as a project folder: the Main flow is your table of contents or your executive summary, while the subflows are the individual chapters. Because subflows share the same variable environment as the Main flow, they can pass data back and forth seamlessly. This shared memory space is what makes subflows so powerful, but it also requires you to be disciplined about how you name and track your variables.
Callout: Subflows vs. Separate Flows It is important to distinguish between a "Subflow" and a "Separate Desktop Flow." A subflow lives inside a single project and shares the global variable scope. A separate flow is an entirely different project that must be called using a specific action (like "Run desktop flow"). Use subflows for organizing logic within one task, and use separate flows when you need to trigger entirely different automations or reuse logic across multiple, unrelated projects.
Why Use Subflows?
- Readability: By grouping actions, you can see the "high-level" logic in the Main flow without getting lost in the technical implementation.
- Reusability: If you have a process—like logging into a website or formatting a date—that you need to perform five times, you write it once in a subflow and call it five times.
- Maintainability: If a website login page changes, you only need to update the "Login" subflow once, rather than hunting through 500 actions to fix every instance of the login process.
- Collaboration: When working on a team, one person can work on the "Data Processing" subflow while another works on the "UI Interaction" subflow, minimizing conflict in the editor.
Not read yet
Creating and Managing Subflows: A Step-by-Step Guide
Creating a subflow is a straightforward process in most modern desktop automation tools. While the interface might vary slightly depending on the specific platform you are using, the core logic remains consistent across the industry.
Step 1: Initialize the Subflow
Navigate to the "Subflows" tab in your editor pane. You will typically see a button labeled "New Subflow" or a plus icon. When you click this, you will be prompted to name your subflow. Always choose descriptive, action-oriented names. Instead of calling it "Subflow1," name it "ProcessCustomerInvoice" or "ConnectToDatabase."
Step 2: Build the Logic
Once the subflow is created, the editor workspace will clear, providing you with a blank canvas. Treat this space as a standalone project. Drag and drop the specific actions required for that task. For example, if you are building an "EmailReport" subflow, include actions to attach the file, input the recipient, and click the send button.
Step 3: Call the Subflow
Return to the Main flow. Find the action titled "Run subflow" (or similar). Drag this action into the Main flow at the exact moment you want the logic to execute. Select your subflow from the dropdown menu. You can now arrange your Main flow like a table of contents:
- Run subflow: InitializeEnvironment
- Run subflow: ExtractData
- Run subflow: ProcessData
- Run subflow: GenerateReport
- Run subflow: CleanUp
Step 4: Testing
Always test your subflows individually if your platform allows, or run the entire flow from start to finish. If an error occurs, the editor will usually highlight the specific subflow where the failure happened, making it much easier to pinpoint the issue compared to scanning a massive list of actions.
Not read yet
Best Practices for Professional Automation
As you move from beginner to advanced, your habits define the quality of your automations. Following these best practices will save you hours of frustration in the long run.
1. Maintain a "Flat" Structure
While you can nest subflows (a subflow calling another subflow), avoid going deeper than two or three levels. Over-nesting creates "spaghetti code" where it becomes difficult to track the execution path. If you find yourself nesting too deeply, it is often a sign that your logic is too complex and should be broken down into smaller, independent flows.
2. Standardize Variable Naming
Since subflows share the same variable space, naming collisions are a common risk. If you use a variable named %Counter% in your Main flow and another variable named %Counter% in a subflow, the subflow will overwrite the value in the Main flow.
- Tip: Use prefixes for variables that are specific to a subflow, such as
%sf_InvoiceTotal%or%sf_EmailAddress%.
3. Clear Documentation
Even if the code seems obvious today, it won't be in six months. Use the "Comment" action liberally inside your subflows. Explain why an action exists, not just what it does. For instance, instead of saying "Click button," say "Click the 'Submit' button to trigger the API validation process."
Warning: Global Variable Overwrites Because subflows share the same memory, a mistake in a subflow can corrupt data in your Main flow. Always be mindful of which variables are being modified within a subflow. If a subflow is meant to calculate a value, ensure it doesn't accidentally overwrite a global configuration variable that is needed later in the process.
4. Modularize Error Handling
Instead of putting complex error handling (like "On Error" blocks) around every single action, create a dedicated subflow for error reporting. If an action fails, use the "On Error" settings to call your HandleError subflow, which might log the error to a file, take a screenshot, and send an email to the administrator.
Not read yet
Practical Examples of Subflow Implementation
To illustrate these concepts, let's look at three common scenarios where subflows are indispensable.
Example 1: The "Login and Initialize" Pattern
Most automations begin by opening an application and logging in. By moving this into a subflow, you can ensure that the login process is consistent across different parts of your project.
Actions in LoginSubflow:
- Launch application.
- Wait for window.
- Populate text field (Username).
- Populate text field (Password).
- Click "Login".
- Wait for dashboard to load.
Why this works: If the login screen changes (e.g., they add a Two-Factor Authentication step), you only update this one subflow. Every part of your automation that calls this subflow will instantly receive the update.
Example 2: Data Extraction and Validation
If you are scraping data from multiple pages, you likely have a loop that extracts information. If you put all the validation logic inside that loop, your main flow becomes unreadable.
Actions in ValidateDataSubflow:
- Check if the extracted date is in the correct format.
- Check if the price is a valid number.
- If invalid, log the issue to a text file.
- If valid, append to the master Excel sheet.
Why this works: By isolating the validation logic, you can easily swap out the validation rules without touching the extraction logic. This separation of concerns is the hallmark of high-quality automation.
Example 3: The "Cleanup" Subflow
A common mistake is leaving applications open or temp files on the disk after an automation finishes. A Cleanup subflow ensures your environment returns to a neutral state.
Actions in CleanupSubflow:
- Close all browser instances.
- Delete temporary CSV files created during the run.
- Move processed files to an "Archive" folder.
- Send a completion email notification.
Not read yet
Common Pitfalls and How to Avoid Them
Even with the best intentions, developers often fall into common traps when working with subflows. Here is how to identify and avoid them.
Pitfall 1: The "Hidden" Dependency
This occurs when a subflow relies on a variable that is expected to be present in the Main flow, but it isn't documented. If you move that subflow to a different project, it breaks.
- Solution: Always pass parameters explicitly if your platform supports them, or keep a "Variable Dictionary" comment at the top of your subflow listing all required inputs.
Pitfall 2: Over-Modularization
Sometimes, people break a flow into subflows that are only one or two actions long. This is "over-engineering." If a subflow doesn't provide a logical grouping or a clear benefit in readability, it might be better to keep those actions in the main flow.
- Solution: Ask yourself: "Will I ever call this logic from another place?" or "Does this group of actions represent a single, clear step in the business process?" If the answer is no, keep it in the main flow.
Pitfall 3: Ignoring Error Propagation
If an error occurs inside a subflow and you do not have an error handling strategy, the entire automation might simply stop or hang.
- Solution: Always configure the "On Error" settings for each subflow call. Decide whether the flow should continue, retry, or stop entirely when a subflow fails.
Callout: The "Single Responsibility" Principle In software development, the Single Responsibility Principle states that a module should do one thing and do it well. Apply this to your subflows. A subflow named
ProcessDatashould process data. It should not also be responsible for opening the browser, logging into the portal, and sending an email. If your subflow is doing too many things, break it into smaller parts.
Not read yet
Technical Considerations: Variable Scope and Data Flow
Understanding how data moves between the Main flow and subflows is critical. In desktop automation, subflows typically share a Global Scope. This means any change you make to a variable in a subflow persists after the subflow finishes and returns control to the Main flow.
The "Pass-by-Reference" Nature
Because variables are global, you don't technically "pass" data into a subflow like you would in languages like Python or Java. Instead, the subflow simply "sees" all the variables currently active in the Main flow. While this is convenient, it is dangerous.
Best Practice for Data Integrity:
If you need a subflow to perform a calculation without affecting your main variables, use temporary variable names. For example, if you are performing a complex math operation in a subflow, do not store the result in the primary %TotalAmount% variable. Store it in %sf_TempResult% and only update the primary variable at the very end of the subflow. This prevents partial data from being accessed if the flow is interrupted.
Quick Reference: Subflow Lifecycle
| Phase | Action | Purpose |
|---|---|---|
| Initialization | Create Subflow | Define the task scope and naming. |
| Configuration | Define Variables | Set up inputs required for the task. |
| Execution | Call Subflow | Trigger the logic from the Main flow. |
| Completion | Variable Update | Ensure results are passed back to Main. |
| Finalization | Cleanup | Return environment to original state. |
Not read yet
Advanced Techniques: Conditional Subflow Execution
You don't always need to run every subflow. Using conditional logic, you can make your automation "smart." For example, you might only want to run a ReportGeneration subflow if a specific flag is set to true or if a certain number of files were processed.
Example: Conditional Call
- Get number of files in folder.
- If
%FileCount%> 0:- Run subflow:
ProcessFiles
- Run subflow:
- Else:
- Run subflow:
SendEmptyNotification
- Run subflow:
This approach makes your automation dynamic. It adapts to the data it finds rather than blindly following a set path. This reduces errors caused by empty files or unexpected scenarios, making your automation more resilient.
Troubleshooting Subflows: A Proactive Approach
Even with perfect design, things will break. Applications update, network connections drop, and file formats change. How you handle these breaks defines your expertise.
1. Use the Debugger
Most desktop automation editors have a "Debug" mode. When you run in debug mode, you can set breakpoints. Set a breakpoint at the start of a subflow. When the execution hits that point, it will pause. You can then inspect the variables to ensure they are what you expect before allowing the subflow to execute.
2. Log Everything
Inside your subflows, add "Write to text file" actions at critical points.
- "Starting Invoice Extraction..."
- "Found 5 invoices..."
- "Finished processing invoice 1 of 5..." If the automation fails, you can open this log file and see exactly how far the subflow got before the crash. This is significantly faster than re-running the entire process and watching it fail in real-time.
3. The "Try-Catch" Pattern
While many platforms have built-in "On Error" blocks, sometimes you need more control. You can create a "Try-Catch" structure using subflows:
- TrySubflow: Contains the main logic.
- CatchSubflow: Contains the error recovery logic.
- Main Flow: Call
TrySubflow. If it fails, callCatchSubflow.
This keeps your error handling logic separate from your business logic, keeping your Main flow clean and readable.
Not read yet
Summary and Key Takeaways
Mastering subflows is the transition point between being a "recorder of actions" and a "developer of automations." By breaking your tasks into logical, reusable components, you create systems that are easier to manage, faster to build, and significantly more reliable.
Key Takeaways for Success:
- Prioritize Modularity: Always break large, complex flows into smaller subflows. If a flow takes more than a glance to understand, it is too long.
- Standardize Naming: Use clear, descriptive names for your subflows and implement a prefix system for variables to avoid accidental overwrites in the global scope.
- Design for Maintenance: Build your subflows with the assumption that the underlying application will change. By isolating UI interactions in subflows, you localize the impact of future updates.
- Think Globally, Act Locally: Remember that subflows share the same variable space. Be disciplined about how you modify variables to prevent side effects in other parts of your automation.
- Document Your Work: Use comments to explain the "why" behind your logic. A well-commented subflow is a gift to your future self and your colleagues.
- Use Conditional Logic: Don't just run subflows linearly. Use conditions to make your automation dynamic and capable of handling different data scenarios.
- Adopt a Defensive Mindset: Use logs, error handling subflows, and debug mode to stay ahead of potential failures. Never assume a subflow will always succeed.
By applying these principles, you will find that your desktop automations become more than just a series of clicks; they become robust, scalable, and professional tools that deliver consistent value. As you continue your journey in automation development, always look for opportunities to refactor your existing flows into subflows. The time you invest in organizing your code today will pay dividends in stability and speed tomorrow.
Not read yet
Frequently Asked Questions (FAQ)
Q: Can I pass arguments to a subflow like a function? A: In most desktop automation tools, subflows do not accept explicit parameters in the way a programming function does. They operate in the global variable scope. You "pass" data by setting the variable in the Main flow before calling the subflow.
Q: How many subflows is "too many"? A: There is no hard limit, but if you have dozens of subflows that are only 1-2 actions long, you have likely over-modularized. Aim for a balance where each subflow represents a complete, logical "step" in your business process.
Q: What happens if I rename a subflow? A: Most modern automation editors will automatically update the references in your Main flow. However, always double-check your "Run subflow" actions after renaming to ensure the link hasn't been broken.
Q: Should I use subflows for simple tasks? A: It depends. If you are doing a simple "Open Excel" and "Close Excel," it might be overkill. Use subflows when the logic is repeatable, complex, or likely to change.
Q: Can I share subflows between different projects? A: Generally, no. Subflows are typically scoped to the project they are created in. If you need to reuse logic across multiple projects, consider creating a separate, standalone flow that can be called by multiple projects, or look into library/shared component features if your platform supports them.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
- Leveraging the Power Automate Ecosystem
- Leveraging the Power Automate Ecosystem Quiz5q
- Cloud Flows vs Desktop Flows
- Cloud Flows vs Desktop Flows Quiz5q
- Designing Desktop and Cloud Flow Automations
- Designing Desktop and Cloud Flow Automations Quiz5q
- Trigger Types for Cloud Flows
- Trigger Types for Cloud Flows Quiz5q
- Target Application and Browser Interactions
- Target Application and Browser Interactions Quiz5q
- Methods for Running Desktop Flows
- Methods for Running Desktop Flows Quiz5q
- Concurrent Flow Execution
- Concurrent Flow Execution Quiz5q
- Attended vs Unattended Desktop Flows
- Attended vs Unattended Desktop Flows Quiz5q
- HTTP Actions in Cloud and Desktop Flows
- HTTP Actions in Cloud and Desktop Flows Quiz5q
- Work Queues for Automation
- Work Queues for Automation Quiz5q
- Designing Custom Actions
- Designing Custom Actions Quiz5q
- Cloud Flow Calling Desktop Flow
- Cloud Flow Calling Desktop Flow Quiz5q
- Child Cloud Flows and Data Passing
- Child Cloud Flows and Data Passing Quiz5q
- External API Calls in Cloud Flows
- External API Calls in Cloud Flows Quiz5q
- Trigger Conditions and Concurrency
- Trigger Conditions and Concurrency Quiz5q
- Timeout and Retry Policies
- Timeout and Retry Policies Quiz5q
- Data Objects and Operations in Cloud Flows
- Data Objects and Operations in Cloud Flows Quiz5q
- Text Parsing JSON XML CSV
- Text Parsing JSON XML CSV Quiz5q
- UI Options in Desktop Flows
- UI Options in Desktop Flows Quiz5q
- Datatables Lists and Custom Objects
- Datatables Lists and Custom Objects Quiz5q
- Subflows in Desktop Flows
- Subflows in Desktop Flows Quiz5q
- External APIs in Desktop Flows
- External APIs in Desktop Flows Quiz5q
- Timeout and Retry in Desktop Flows
- Timeout and Retry in Desktop Flows Quiz5q
- Custom Actions in Desktop Flows
- Custom Actions in Desktop Flows Quiz5q
- Flow Control and Loops
- Flow Control and Loops Quiz5q
- Expressions in Cloud Flows
- Expressions in Cloud Flows Quiz5q
- Variable Actions for Flows
- Variable Actions for Flows Quiz5q
- Secure Input and Output Data
- Secure Input and Output Data Quiz5q
- Desktop Flow Priority and Queues
- Desktop Flow Priority and Queues Quiz5q
- Exception Handling Blocks
- Exception Handling Blocks Quiz5q
- Business Exception Error Handling
- Business Exception Error Handling Quiz5q
- Work Queues in Flows
- Work Queues in Flows Quiz5q
- Building a Custom Connector
- Building a Custom Connector Quiz5q
- Custom Connector Authentication
- Custom Connector Authentication Quiz5q
- Custom Connector Policy Templates
- Custom Connector Policy Templates Quiz5q
- Code in Custom Connectors
- Code in Custom Connectors Quiz5q
- Credential Management Practices
- Credential Management Practices Quiz5q
- On-Premises Data Gateway
- On-Premises Data Gateway Quiz5q
- Dataverse Solutions Components
- Dataverse Solutions Components Quiz5q
- Machine and Machine Group Requirements
- Machine and Machine Group Requirements Quiz5q
- Machine Registration Management
- Machine Registration Management Quiz5q
- Machine Group Management
- Machine Group Management Quiz5q
- Load Balancing Desktop Flows
- Load Balancing Desktop Flows Quiz5q
- Run Queue Operations
- Run Queue Operations Quiz5q
- Analyzing Flow Run History
- Analyzing Flow Run History Quiz5q
- Power Automate Analytics Dashboard
- Power Automate Analytics Dashboard Quiz5q
- Desktop Flow Monitoring
- Desktop Flow Monitoring Quiz5q
- Automation Performance Optimization
- Automation Performance Optimization Quiz5q
- Troubleshooting Flow Failures
- Troubleshooting Flow Failures Quiz5q
- Center of Excellence RPA Analytics
- Center of Excellence RPA Analytics Quiz5q
No PL-500 practice exam yet
Your points already work on 76 Amazon, CompTIA and Microsoft exams.
See the exams