Input and Output Variables in Power Automate Desktop

 

Input and Output Variables in Power Automate Desktop

When creating automation workflows with Power Automate Desktop (PAD), one of the most important concepts you’ll need to understand is variables. Specifically, input and output variables allow you to pass data between different parts of your flow, making your automations more dynamic and reusable.

In this blog post, we’ll dive into the basics of input and output variables, explain how they work, and show you how to use them with simple examples.


What are Variables in Power Automate Desktop?

A variable in Power Automate Desktop is a placeholder used to store data that can be referenced or changed throughout the flow. Variables are essential because they allow you to:

  • Store dynamic data (like user input, file paths, or calculations).
  • Pass data between actions in your flow.
  • Use data from previous steps in later actions.

There are different types of variables, such as text, numbers, dates, and more. Input and output variables are special types of variables used to handle data between subflows or between your main flow and subflows.

What are Input and Output Variables?

Input variables are values or data passed into a flow or subflow, while output variables are data or results returned from a flow or subflow.

  • Input Variables: These are used to send data into your flow. For example, when you call a subflow, you can pass data to it via input variables.
  • Output Variables: These store the result of a flow or subflow and can be used to send the result back to the calling flow.

Using input and output variables helps to make your automation modular and dynamic, as you can reuse subflows and pass different data to them each time.


How to Use Input and Output Variables

Let’s walk through how to create and use input and output variables in a real-world example.

Example Scenario: Sending Personalized Emails

Imagine you have a process where you want to send a personalized email to multiple employees. You’ll use a main flow that retrieves employee data and then calls a subflow to send the emails. The employee’s name and email address will be passed as input variables to the subflow, and the result (whether the email was successfully sent or not) will be returned as an output variable.


Step 1: Create a Subflow for Sending Emails

First, we need to create the subflow that will handle sending the emails.

  1. Create a new subflow and name it SendEmailSubflow.

  2. Inside the subflow, add the action Send an Email to send an email. This action will use two input variables: the email address and the employee's name.

  3. Define the input variables for the subflow:

    • EmailAddress (type: Text)
    • EmployeeName (type: Text)
  4. Set up the Send an Email action to use these input variables to fill the recipient’s email address and the subject/body of the email. You can use the following for the subject:

    • Subject: "Hello {EmployeeName}, your report is ready!"
    • Body: "Dear {EmployeeName},\n\nYour report has been processed."
  5. Define the output variable:

    • EmailStatus (type: Text) — This variable will store the result of the email sending action (e.g., "Success" or "Failed").

Now, this subflow will accept two inputs (email address and name), send the email, and then return a status.


Step 2: Create the Main Flow

Next, let’s create the main flow that will use the subflow to send emails to multiple employees.

  1. Create a new main flow called MainFlow.

  2. In this flow, you can retrieve a list of employees from an Excel file, a database, or a simple list. For this example, let's assume the employee data is stored in a list.

    Example List:

    • Employee 1: John Doe, john.doe@example.com
    • Employee 2: Jane Smith, jane.smith@example.com
  3. Use a For Each action to loop through each employee and call the SendEmailSubflow for each one.

Steps:

  1. Create a list of employee names and email addresses. You can store this list in a List variable.
  2. Use a For Each loop to iterate over this list. Inside the loop, you will call the subflow for each employee.
  3. Pass the EmployeeName and EmailAddress as input variables to the SendEmailSubflow.
  4. Capture the result of the subflow (email sending status) as an output variable (EmailStatus).

Step 3: Putting It All Together

Let’s summarize the full process in the MainFlow:

  • Create a List of Employees: Store employee data (name and email) in a list.
  • For Each Loop: Iterate through the employee list.
  • Call Subflow: For each employee, pass the name and email to the SendEmailSubflow as input variables.
  • Capture the Output: After the email is sent, store the result (whether the email was successfully sent) in the EmailStatus output variable.

Example Flow:

  • Action: Create List (Employees: John Doe, john.doe@example.com; Jane Smith, jane.smith@example.com).
  • Action: For Each (Loop through Employee List).
    • Inside the loop:
      • Call Subflow (SendEmailSubflow)
        • Input Variables:
          • EmailAddress = Employee's email address
          • EmployeeName = Employee's name
        • Output Variables: Capture EmailStatus (whether the email was sent successfully).
      • Action: Log Message (Output: EmailStatus).

Step 4: Using the Output Data

Once the email has been sent, the subflow will return an output variable (e.g., "Success" or "Failed"). In the main flow, you can use this output data to:

  • Log a message about whether the email was sent.
  • Perform further actions based on the result (e.g., retry sending if it failed).

You could add a conditional check to decide what to do next:

  • If EmailStatus = "Success": Log "Email sent successfully."
  • If EmailStatus = "Failed": Log "Email failed, retrying."

Why Are Input and Output Variables Important?

Using input and output variables is key to making your flows dynamic, modular, and reusable:

  • Input Variables: These allow you to pass data into subflows or actions, making them flexible and adaptable to different scenarios.
  • Output Variables: These let you capture the results of actions or subflows and use that data in subsequent steps, allowing your automation to respond based on real-time results.

In our example, you can use the SendEmailSubflow for multiple employees with different email addresses and names, without needing to recreate the entire email-sending process each time.


Best Practices for Using Input and Output Variables

  1. Name Your Variables Clearly: Use descriptive names for your input and output variables (e.g., EmailAddress, EmployeeName, EmailStatus). This makes it easier to understand what each variable represents.

  2. Use Variables for Dynamic Data: Whenever you need to handle dynamic data (like user inputs, values from external sources, or results from actions), use variables to store and pass that data.

  3. Reuse Subflows: When possible, create subflows that use input variables, so you can reuse them in multiple places. This will make your automation more efficient and easier to maintain.

  4. Check for Output: Always check the result (output variable) of a subflow or action, especially for operations that could fail (like file operations or network requests).


Conclusion

Input and output variables are fundamental to creating flexible, reusable, and efficient workflows in Power Automate Desktop. They enable you to pass data into and out of actions and subflows, making your automation dynamic and adaptable.

In this post, we’ve seen how to:

  • Create input and output variables.
  • Pass data between main flows and subflows.
  • Use variables to log and track the results of each action.

By mastering input and output variables, you can design smarter and more modular automations that can scale with your needs.