Skip to main content

How to Create Environment Variables for a SharePoint Site and List in Power Apps

· 11 min read
Jagdish Kumawat
Founder @ Dewiride

A canvas app that reads a SharePoint list normally has the site's address and the list built into it. Move the app to another organization and it still points at the old site. Environment variables fix that: the app asks the variables where its data is, and each environment gives them its own values.

What You Will Create​

An environment variable is a named setting that lives in a solution. Its type decides what it holds; the Data source type points at data through a connector. For SharePoint you need one variable per site, and one per list:

  • Site variable: holds the site's address.
  • List variables: each points at a site variable, and holds the list's ID, not its name.

Each has a current value, which is what this environment uses. When the solution is installed somewhere else, the installer gives the variables that environment's values, and the app follows.

This guide creates the three variables for the Career Development Plan series:

Display nameNameParameter typeCurrent value
Career Development Plan Sitedewiride_CareerDevelopmentPlanSiteSiteThe Career Development Plan site
RoleCompetenciesdewiride_RoleCompetenciesListListThe RoleCompetencies list
CompetencyResponsesdewiride_CompetencyResponsesListListThe CompetencyResponses list

Prerequisites​

Step 1: Start a New Environment Variable​

Open your solution, then select New → More → Environment variable.

The solution's New menu open on More, with the submenu listing Choice, Component Library, Connection Reference, Connection Role, Environment variable outlined in red, Setting, Templates, Web resource and Other

The New environment variable panel opens.

Step 2: Choose SharePoint and Create the Connection​

Do this part first, before you type any names. Power Apps lists your sites and lists through a SharePoint connection, and creating one from this panel only goes smoothly while the form is still empty.

  1. Set Data Type to Data source. The other types are Decimal number, JSON, Text, Yes/No and Secret.
  2. Set Connector to SharePoint.
  3. Open Connection. If you already have a SharePoint connection, choose it and go to Step 3. If not, select + New connection.

The Data Type set to Data source, Connector set to SharePoint, and the Connection dropdown open showing + New connection

If you've already typed a display name, Power Apps asks whether to discard your changes instead. That's covered in Fixed: "Are You Sure You Want to Discard Changes?".

A new browser tab opens on Connect to SharePoint:

The Connect to SharePoint dialog with an optional Display name box, How do you want to connect to your data? set to Connect directly (cloud-services), and the Create button outlined in red

Leave Connect directly (cloud-services) selected and select Create. A Microsoft sign-in window asks you to pick an account: choose the one you're signed in with. The tab then lists the new connection as Connected:

The Connections page listing a SharePoint connection named admin@example.com with Last modified 2 seconds ago and Status Connected

Close that tab. Back in the first tab, Power Apps shows Apply changes: If you've created any new connections, Refresh to add them to the connection list. You will not lose your progress. Select Refresh.

The Apply changes dialog saying If you've created any new connections, Refresh to add them to the connection list. You will not lose your progress, with Refresh outlined in red

Connection now shows your new connection. Power Apps uses it only to list your sites and lists: Microsoft notes that the connection isn't stored in the environment variable.

Step 3: Name the Site Variable​

Now fill in the rest:

FieldExample
Display nameCareer Development Plan Site
NameFilled in as dewiride_CareerDevelopmentPlanSite. The dewiride_ part is your publisher's prefix
DescriptionThe SharePoint site that holds the Career Development Plan lists.
Parameter TypeSite

The New environment variable panel with Display name Career Development Plan Site, Name dewiride_CareerDevelopmentPlanSite, the description, Data Type Data source, Connector SharePoint, Connection admin@example.com, Parameter Type Site and the Current site value heading

Step 4: Set the Site​

Under Current site value, select + New site value. A tip may appear about choosing whether to export variable values. Select Done; you'll see that setting in a moment.

A tip saying Plan on exporting? Read this. There's a new setting that lets you include or exclude variable values when exporting. Access it under Advanced, next to the Current site box

Open Current site. It lists the sites your connection can see. Choose your site:

The Current site dropdown open with Career Development Plan - https://contoso.sharepoint.com/sites/CareerDevelopmentPlan outlined in red, and a second entry called Pages

Then open Advanced:

The bottom of the panel with Current site set to the Career Development Plan site, Advanced expanded with Export value No and the text The current value will be removed from the exported solution file, an empty Default Value, and Save outlined in red

  • Default Value: leave it empty. A default value travels inside the solution, while the current value is this environment's. When someone installs a solution whose variable has neither, Power Apps asks them for a value, which is exactly what you want for a site address.
  • Export value: whether the current value goes into the exported solution file. No keeps your site out of it. Be aware that when the example's variables were reopened later, this switch showed Yes even though No had been saved. Don't rely on it alone: check the solution's contents before you export it.

Select Save.

Step 5: Create the List Variables​

Create one more variable per list, the same way: New → More → Environment variable, Data source, SharePoint, your connection. This time:

FieldFirst listSecond list
Display nameRoleCompetenciesCompetencyResponses
NameType RoleCompetenciesList after the prefixType CompetencyResponsesList after the prefix
DescriptionThe SharePoint list of competencies and levels for each job title.The SharePoint list of employees' responses and their managers' reviews.
Parameter TypeListList
SiteCareer Development Plan SiteCareer Development Plan Site
Current listRoleCompetenciesCompetencyResponses

Give each list variable the list's own name as its display name. When a canvas app connects to a list through a variable, the app names the data source after the variable's display name. A variable called RoleCompetencies List becomes a data source called 'RoleCompetencies List', which every formula then has to wrap in quotes. Microsoft's coding guidelines name data sources in PascalCase, without spaces. The Name keeps List at the end, so the variables are still easy to tell apart from the lists themselves.

With Parameter Type set to List, Site asks for a site variable, not an address. Choose the one from Step 3:

The list variable's panel with Name dewiride_RoleCompetenciesList, the description, Data source, SharePoint, the connection, Parameter Type List, and the Site dropdown offering Career Development Plan Site, outlined in red

That link is what lets the list follow the site to another environment. Under Current list value, select + New list value and open Current list. It lists the site's lists:

The Current list dropdown open above the Current list box, offering CompetencyResponses, Documents and RoleCompetencies, with RoleCompetencies outlined in red

Choose the list. The dropdown shows names, but Power Apps stores the list's ID, so renaming the list later doesn't break the variable. Leave Default Value empty again, and select Save.

The bottom of the list variable's panel with Site Career Development Plan Site, Current list RoleCompetencies, Advanced showing Export value No and an empty Default Value, and Save outlined in red

Repeat for the second list.

Step 6: Check the Solution​

In the solution, select Environment variables in the Objects pane. All three are there:

The solution's Environment variables view listing Career Development Plan Site, CompetencyResponses and RoleCompetencies, each of type Environment Variable, with Environment variables (3) selected in the Objects pane

To change one later, select its name. If editing a list variable shows We are unable to find the list, see Fixed: "We Are Unable to Find the List".

Common Mistakes​

MistakeWhat happensDo this instead
Typing names before choosing New connectionPower Apps asks to discard your changesCreate or choose the connection first
Display name RoleCompetencies ListThe app's data source is 'RoleCompetencies List'Use the list's own name
Filling in Default ValueYour site goes into the solution, and installers aren't askedLeave it empty; use the current value
One variable for site and list togetherSharePoint needs bothOne site variable, plus one per list
Choosing the list in Recent sites in Power Apps Studio laterThe app ignores the variablesUse the Advanced tab, as Part 3 of the series shows

Troubleshooting​

SymptomLikely causeFix
Connection offers only + New connectionYou have no SharePoint connection yetCreate one, as in Step 2
Current site doesn't list your siteThe connection's account can't open the siteUse an account with access to the site
Site for a list variable is emptyNo site variable exists yetCreate the site variable first
A changed value doesn't show in the appValues are cachedMicrosoft notes it can take up to an hour; test in a new browser session

FAQ​

Where is the connection stored?​

Not in the environment variable. The connection is yours, and Power Apps only uses it to list sites and lists while you edit. Each person who uses the app later connects with their own account.

What exactly does a list variable hold?​

The list's ID, a GUID, plus the link to its site variable. Microsoft's documentation calls this out: it's the ID, not the list's display name.

Can I rename a variable later?​

You can change its display name and description. The Name is fixed once saved.

Do environment variables make the app premium?​

No. Microsoft's environment variables FAQ is explicit that they don't need premium licenses.

Conclusion​

The solution now has a site variable and one variable per list, each pointing at real SharePoint data through its current value. The list variables carry the lists' own names, so the app's data sources will too. The SharePoint connection was created along the way, from the panel itself.

Next, create the app that uses them: How to Create a Canvas App Inside a Solution in Power Apps.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.