Add UI elements and test
You can set an output variable using a UI element. The UI element gives you a value, but you need to store it for later use. That's what the output variable is for.
The input variables are associated with steps. Output variables are not associated with action steps because the goal is to get information rather than complete an action, such as selecting. So, a new action is required to set an output variable.
The following video demonstrates the steps that you'll complete in this unit.
Ensure that the desktop application that's relevant to your flow is running during this process. On the Actions Pane, search for the data extraction functions, or expand UI automation and Data extraction. Select and drag Get details of the UI element in window to the appropriate step in your flow. For the Contoso Invoicing flow, place the action just after your Populate text field in window steps.
In the next dialog, select expand the UI element dropdown menu and then select Add UI element.
The Power Automate designer minimizes, revealing your desktop application and a small window that contains your tracking session. Unlike when you record actions, the tracking session is looking for you to select an element to capture. You can take actions without affecting the tracking session. To choose the element, hover your cursor over it until you see a red border, hold down the Ctrl key, and then left-click the element (in this case Invoice ID) to record it in the tracking session.
Once you make the selection, Power Automate takes you back to the flow. Your image should look similar to the following:
This action automatically creates a variable called AttributeValue as an output that you can refer to in later actions within Power Automate Desktop.
When you retrieved the element (Invoice ID) from the application, an ID value was returned based on a new invoice that was being created. To ensure that your value is dynamic, you'll need to complete a few more steps.
Select the stacked paper icon on the right side of your screen. Find the element that you selected. The element should start with Text, and the text that you added should be encased in single quotation marks, as shown in the following screenshot. Select the ellipsis (...) and, in the menu, select Edit.
In the next dialog, if you hover your cursor over the text, the ellipsis (...) will show. Select the ellipsis and then select Edit selector.
Select the element that you want to edit and then ensure that the Name Equal to [your text value] is not selected. This allows the value to be dynamic rather than static. Select Update and then close the Edit selector dialog.
Now that you've gathered a dynamic UI element, you can set the output variable. In the step you just inserted, expand the Variables produced, ensure that the toggle is selected, and select your InvoiceID output variable.
If you forget the names of your variables, you can always view them by selecting {x} in the upper-right corner of Power Automate designer.
You now know how to define and set the input and output variables. These variables allow you to make your desktop flows more powerful and dynamic.
Save and Run your flow to see your work in action.
Your flow should open the Contoso Invoicing app, select the Invoices, create a new entry, save the entry, and return the new invoice number to your desktop flow as the value for your InvoiceID output variable.
Next, let's check what you've learned in this module.