Simplify Importing & Exporting Power Apps With Datasource Environment Variables

Simplify Importing & Exporting Power Apps With Datasource Environment Variables

When moving Power Apps between environments they remain connected to the same SharePoint lists. This is a problem because we don’t want to manually delete connections inside a live app and make new ones. It’s alot of work and anytime an app is changed errors can be introduced. Wouldn’t it be nice if the app was automatically connected to the proper SharePoint lists when moved? This can be done using datasource environment variables.

In this article I will show you how to simplify importing and exporting Power Apps between environments using datasource environment variables.

Table of Contents:
Introduction: The Appointments App
Creating Development And Production SharePoint Lists
Adding A New Canvas App Into A Solution
Generating Datasource Environment Variables
Removing Environment Variable Values
Export Solution From Development
Import Solution To Production
Testing The Production App




Introduction: The Appointments App

The appointments app is used by salespeople at a roofing company to keep track of client meetings. There are two power platform environments, each with their own copy of the app:

  • Development – in this environment developers work to build new features into the app
  • Production – in this environment a ‘live’ version of the app is used by salespeople

Once a new version of the app is completed in the development environment it gets pushed to the production environment.



Appointments data is stored in a SharePoint list. There are 2 copies of the SharePoint list:

  • Development – in this Sharepoint list fake data has been created for testing and is found on the development site
  • Production – in this SharePoint list real data has been created for the salespeople and is found on the live site.


Developers need to ensure the app is connected to the proper SharePoint list when moved from Development to Production.




Creating Development And Production SharePoint Lists

We will start by creating a SharePoint list called Appointments on the Development SharePoint site. Add the following columns:

  • Title (single line text)
  • ContactName (single line text)
  • StreetAddress (single line text)
  • StartDateTime (date & time)

Insert this “fake data” into the list:

TitleContactNameStreetAddressStartDateTime
Test AppointmentJohn Smith123 Fake Street6/1/2021 10:00AM
Test AppointmentJane Smith456 Fake Street6/2/2021 10:00AM
Test AppointmentJohn Smith789 Fake Street6/3/2021 10:00AM
Test AppointmentJane Smith123 Fake Street6/4/2021 10:00AM
Test AppointmentJohn Smith456 Fake Street6/5/2021 10:00AM


Then create another SharePoint list called Appointments on the Production SharePoint site. Include this “real data”:

TitleContactNameStreetAddressStartDateTime
AppointmentBen Harrington100-1st Street North6/1/2021 10:00AM
AppointmentMelissa Stripe45 Blue Water Cove6/1/2021 11:00AM
AppointmentJennifer Swan80 Fairway Lane6/1/2021 2:00PM
AppointmentDavid Brodie202-2nd Avenue West6/2/2021 9:00AM
AppointmentDanielle Brown70 Green Valley Bay6/2/2021 3:00PM




Adding A New Canvas App Into A Solution

We will transfer the Appointments app from the development environment to the production environment using a “Solution.” Open the development environment and click Solutions on the maker portal’s side-menu. Then choose New Solution. Setup the Solution as shown below and click create.



Add a new tablet form factor canvas app to the solution.



Open the new canvas app we created in Power Apps Studio. Create a titlebar by inserting a label with the word “Appointments” and giving it a fill color. Then insert a blank vertical gallery in the remaining portion of the screen as shown below.




Generating Datasource Environment Variables

We want the copy of the app in development to use the “fake data” and the copy of the app in production to use the “real data.” Connecting the app to a datasource environment variable instead of connecting to the SharePoint list directly makes it easy to swap the connection reference when moving the app between environments.

To do this, open the advanced settings menu and turn the Automatically create environment variables when adding data sources feature on.



Now go back to the editor and add data using the SharePoint connector. Select your development SharePoint site…



…and choose the Appointments SharePoint list.



When we click connect we see a green notification message at the top of the screen saying “one or more environment variables were created.”



Use Appointments as the datasource for the gallery and insert several labels to display the list’s data as shown below. Then save the app and publish it.




Removing Environment Variable Values

We can see two environment variables have been created inside the solution: one for the SharePoint site reference and another for the SharePoint list reference. Before we move the app from Development to Production we must clear their current values.



Edit the site environment variable and remove its value from the solution…



… and do the same thing for the list environment variable as well.




Export Solution From Development

Now we are ready to export the solution. Click the Export button…



…and click next through all of the prompts. Choose a managed solution on the final screen and click Export.



After a few minutes a zip file containing the app and environment variables will download to your computer.




Import Solution To Production

Once the download has completed browse to the production environment.



Go to Solutions and click Import.



Click Next on all of the prompts that appear. When you reach the final screen called Environment Variables choose the production SharePoint site and the production SharePoint list. Then click import.




Testing The Production App

We’re done! To confirm pushing the app to production was successful open it and make sure it is showing data from the production SharePoint list.





Questions?

If you have any questions or feedback about Simplify Importing & Exporting Power Apps With Datasource Environment Variables please leave a message in the comments section below. You can post using your email address and are not required to create an account to join the discussion.

Matthew Devaney

Subscribe
Notify of
guest
22 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Chloe
Chloe
1 year ago

Hi Matthew, great content! I just subscribed Friday! Iā€™m not able to comment on the post I actually need help with – weirdly. Looking at adding an other option in power apps and have the same question as Cindy.

Haroldbk
Haroldbk
1 year ago

That worked nicely but there was not a green notification banner when the environmental variables were added.

Ramesh Mukka
Ramesh Mukka
1 year ago

Do solutions require premium license?

Eric
Eric
1 year ago

Hm. Looks like this only works if you have two Sharepoint sites with the same list name.

I typically have one Sharepoint site with two lists; “one_dev” and “one_prod”.

Doesn’t appear that Solutions support this pattern, correct?

I have a home grown method for handling this that has worked for years. Yes, its manual. After import to PROD I have to open the app and set varEnv to “PROD”. But thats not a big deal.

Example:

OnStart:

Set(varEnv, “DEV”)

All ClearCollect(), Patch(), etc:

If(
varEnv = “DEV”,
ClearCollect(colRecords, one_dev),
varEnv = “PROD”,
ClearCollect(colRecords, one_prod)
)

Last edited 1 year ago by Eric
Ramesh Mukka
Ramesh Mukka
1 year ago

How about adding existing apps and flows to the new solution? Once I add the app to the solution, do I have to remove the data sources and add them back to create the environment variables?

Krishan
Krishan
1 year ago

We are trying to create a solution package for our SharePoint list based Canvas app so that we can deploy this solution from Dev to Prod environment by just updating the environment variables SharePoint Site and List data source while importing the solution. We are using SharePoint Data Source Environment variables for this task so that there would not be any need to update the data source after the app is imported to production.

Everything works fine but when we are tested our app deployed in the production, we found Choices fields in the app were creating issues for us. It seems choice field is still trying to get the reference from old dev site list GUID. See the attached error image.

Any help on this will be appreciated.

ChoicesError.png
Brian
Brian
10 months ago
Reply to  Krishan

I’m having this exact same issue. It doesn’t seem to work for choice field dropdowns when imported into the new environment. My app is displaying correct data in the gallery control, but all the choice fields on the form are broken after the import. Has anyone found a solution for this or have any suggestions?

Brian
Brian
8 months ago
Reply to  Brian

I had been struggling with this for many months, and after working with Microsoft support the issue has now been fixed in that latest Power Apps version 3.22022.31 which just became available. I can now promote my solutions to other environments and the choice and people fields are working!

Glib Pronskikh
Glib Pronskikh
11 months ago

Hello Matthew, thank for the article. Can you please clarify something for me. I have already existing app with 6 connected sharepoint lists. I want now to duplicate this app 5 times, and connect to different lists, with identical structure. How can I do it with environmental variables? Thank you in advance.

pietro
pietro
9 months ago

just great!

Billy
Billy
7 months ago

Great article! But per my understanding this datasource type works only for Sharepoint, right? What if my canvas app is bound to an excel file on a Onedrive business folder? The system doesn’t create any environment variable and also when importing into a different tenant/environment obviously stops working. Do you know how we can move apps based on excel for example? Thank you.

Michel LAPLANE
Michel LAPLANE
29 days ago

What about export to another tenant it seem’s that it does not work.
Did we need to create environment variable manually on the other tenant?