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:
|Test Appointment||John Smith||123 Fake Street||6/1/2021 10:00AM|
|Test Appointment||Jane Smith||456 Fake Street||6/2/2021 10:00AM|
|Test Appointment||John Smith||789 Fake Street||6/3/2021 10:00AM|
|Test Appointment||Jane Smith||123 Fake Street||6/4/2021 10:00AM|
|Test Appointment||John Smith||456 Fake Street||6/5/2021 10:00AM|
Then create another SharePoint list called Appointments on the Production SharePoint site. Include this “real data”:
|Appointment||Ben Harrington||100-1st Street North||6/1/2021 10:00AM|
|Appointment||Melissa Stripe||45 Blue Water Cove||6/1/2021 11:00AM|
|Appointment||Jennifer Swan||80 Fairway Lane||6/1/2021 2:00PM|
|Appointment||David Brodie||202-2nd Avenue West||6/2/2021 9:00AM|
|Appointment||Danielle Brown||70 Green Valley Bay||6/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.
Did You Enjoy This Article? 😺
Subscribe to get new Power Apps articles sent to your inbox each week for FREE
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.