Skip to main content

How to Use Environment Variables in a Power Automate Flow

· 6 min read
Jagdish Kumawat
Founder @ Dewiride

A flow in a solution shouldn't have a fixed SharePoint site and list: in the next environment, they're different. Put environment variables in the fields instead. In the new designer, choose Enter custom value, open the dynamic content list, and pick the variable; it's listed under Parameters.

Microsoft's environment variables in Power Automate article says: Environment variables can be used in solution cloud flows since they're available in the dynamic content selector. All types of environment variables can be used in triggers and actions.

The example is the approval flow of the Overtime Timesheet app, which reads the site, the OvertimeEntries list and the Departments list from variables.

Prerequisites​

Step 1: Switch the Field to a Custom Value​

Site Address and List Name are drop-downs of real sites and lists. Open the drop-down and choose Enter custom value; the field becomes a text box that accepts dynamic content.

In the classic designer, where the example flow was created, the trigger's fields didn't offer dynamic content, so I picked the site and list from the drop-downs first and replaced them in the new designer.

Step 2: Pick the Site Variable​

Select the field, then the lightning button that appears beside it, Insert dynamic content. Type part of the variable's name in the search box. The variables are listed in a group called Parameters, each with its schema name in brackets:

The trigger's pane with an empty Site Address marked 'Site Address' is required., and the dynamic content list searched for Overtime, showing the Parameters group with OvertimeEntries (dewiride_OvertimeEntriesList) and Overtime Timesheet Site (dewiride_OvertimeTimesheetSite), the second one outlined

Select the site variable. It goes into the field as a token.

Step 3: Pick the List Variable​

Do the same for List Name, with the list's variable:

The trigger's pane with Site Address set to the Overtime Times… token and an empty List Name marked 'List Name' is required., and the dynamic content list searched for Overtime, showing the Parameters group with OvertimeEntries (dewiride_OvertimeEntriesList) outlined above Overtime Timesheet Site (dewiride_OvertimeTimesheetSite)

Both fields now hold variables:

The trigger's pane with Site Address set to the token Overtime Times… and List Name set to the token OvertimeEntries…, each with the environment variable icon, and the line Connected to Overtime Timesheet SharePoint.

Step 4: Use the Variables in Every SharePoint Action​

Every SharePoint action needs them too. The example's Get the department reads the Departments list with the site variable and the Departments variable:

The Get the department pane with Site Address set to the Overtime Times… token, List Name set to the Departments (d… token, Id set to the DepartmentId token, and the line Connected to Overtime Timesheet SharePoint.

In Code view, a variable token is a parameters() expression with the variable's display name and schema name:

Site Address in Code view
@parameters('Overtime Timesheet Site (dewiride_OvertimeTimesheetSite)')

When a Variable's Value Changes​

Microsoft's article lists a limitation: When environment variable values are changed directly within an environment instead of through an ALM operation like solution import, flows will continue using the previous value until the flow is either saved or turned off and turned on again. After changing a value by hand, save the flow or turn it off and on.

Common Mistakes​

MistakeWhat happensDo this instead
Picking the site from the drop-down and leaving itThe flow points at this environment's site everywhereUse the variable
Using variables in the trigger but not the actionsActions still read this environment's listsUse them in every SharePoint action
Changing a variable's value and expecting the flow to followIt keeps the old valueSave the flow, or turn it off and on

Troubleshooting​

SymptomLikely causeFix
No variables in dynamic contentThe field is still a drop-downEnter custom value first
The variables don't appear at allThey're in a different solutionAdd them to the flow's solution
The flow still uses the old siteThe value was changed by handSave the flow, or turn it off and on

FAQ​

Do I need one variable per list?​

Yes, one per list, plus one for the site. A SharePoint list variable is linked to its site variable.

Do the variables work in the classic designer?​

The example flow's trigger, in the classic designer, didn't offer them; the new designer did. Open the flow from My flows to use the new designer.

Conclusion​

In a solution flow, put environment variables in SharePoint's Site Address and List Name: Enter custom value, then pick the variables from dynamic content, under Parameters. Do it in the trigger and in every SharePoint action.

Additional Resources​