Moving your Power Apps apps and flows between environments or tenants doesn’t need to be painful! Microsoft has built in an effective method of doing this in the form of Solutions. Using Solutions in combination with Environment Variables is an efficient way of making your creations portable while at the same time removing a lot of the hassle that usually tags along when you’ve got SharePoint lists involved.
Click the video below to get started!
Click the link below to see more of Shane Young's YouTube channel:
Defining Power Platform solutions and environment variables (1:20)
A Power Apps Solution is an object in the Power Platform that allows you to bundle together the various components of your Power Platform project. Solutions can contain Apps (both Canvas and Model-Driven), Power Automate flows (both Cloud and Desktop), PowerBI Dashboards, Dataverse tables, Component Libraries, plus a whole lot more. Nearly anything related to the construction of your solution can go into the aptly named “Solution” for easy transport.
As you may have noticed, missing from the list was SharePoint Lists. Unfortunately, you can’t package up a SharePoint list to move around like you can those other elements. What you can do, however, is use an Environment Variable. You’ll link your app to the environment variable, and that variable will be configured in each environment to point at the corresponding SharePoint list. So while you can’t include the SharePoint list in your Solution, involving environment variables is the next best thing, and through the rest of this article (which follows Shane’s video on the subject) you’ll learn how to do just that! Let’s get started!
Create a solution (3:39)
Using the Environment selector in the top-right corner of the screen, switch to your Development environment. (If you don’t have a developer environment yet, pause what you’re doing, and follow these instructions from Microsoft on setting one up, it’s free! Don’t worry, we’ll wait…)
In the menu on the left, click on Solutions.
If you don’t see Solutions, you might need to click … More and you’ll find it in there!
On the Solutions screen, click + New solution
Give the Solution a descriptive Display name. The Name field will follow suit, but just remove any unacceptable characters from the Display name, like spaces, hyphens, etc.
Next you’ll need to select a Publisher. Automatically, there will be a default publisher available. The Publisher basically drives what the prefix of all the objects in the Solution will use in their naming. This is especially important in Solutions involving Dataverse, where calling the objects by their system names (including that prefix) comes into play. Since we aren’t doing that in today’s example, sticking with the default publisher is fine, but if you will be building Solutions in the future, setting up a custom publisher with a friendlier prefix will be helpful.
You can leave everything else at its default setting and click Create.
Once your Solution is created, you’ll be sitting at the screen showing your brand new, empty solution. Here you want to click + New, hover over Apps and let’s add a Canvas app.
Give your app a name and choose its format. For our purposes, we’ll choose a Tablet app. And click Create.
Make sure you save your app.
Once the initial save operation has completed, click Settings.
On the General page, scroll down and find the setting “Automatically create environment variables when adding data sources.” Toggle this setting to ‘On’.
Save your app again. When the save completes, click the Back button in the Power Apps toolbar, click Leave on the dialog box. This will exit out of the app.
When you land back in the view of objects in your solution, click the 3 dots to the right of your app name and choose Edit to get back into the Studio to continue building your app.
Before we get back into building the app, first let’s open a new tab and go to your tenant’s SharePoint. Go to a SharePoint site where you have the ability to create a new list. (If you don’t have access permissions to create lists, send a request to whoever handles List creation for your tenant and include the details in steps 18-20 to have them build the List you need.)
On the landing page for the SharePoint site, click the Gear icon in the top-right and choose Site contents.
Click + New and choose List and choose Blank list.
Give the list a name and optionally a description, uncheck the “Show in site navigate” box and finally click Create.
On SharePoint List naming: Always remember that you only get to name your SharePoint List once. You can edit the name, but this is a cosmetic change only, deep down the list’s name never changes. Since the list name becomes part of the URL to the list, SharePoint will automatically replace special characters and spaces in the list name with URL-friendly codes. If you put a space in your list’s name, for example, “List Name”, SharePoint will create a list with the name: List%20Name. You should always, always, always name your SharePoint List with no spaces or special characters. You can then go back into the List Settings later and rename the list with spaces and special characters so it displays how you prefer, but the underlying list name will be that simple name with no spaces and special characters, which makes for a much better experience when working with the list in the Power Platform.
In your list, add 2 columns:
A number column named MyNumber
A choice column named MyChoice using the default options of Choice 1, Choice 2 and Choice 3.
Add some sample data to the list:
Title: Item 1, MyNumber: 1, MyChoice: Choice 1
Title: Item 2, MyNumber: 2, MyChoice: Choice 2
Title: Item 3, MyNumber: 3, MyChoice: Choice 3
Back in your app, click the Data icon in the left-side navigation bar and choose Add Data.
Search for SharePoint and choose the SharePoint result (not the SharePoint Sites Dataverse result).
If you’ve connected to SharePoint in this environment previously, choose the connection you already have set up, otherwise, click Connect directly (cloud services) and click Connect.
Choose the site containing the SharePoint List.
Finally choose the List you created and click Save.
Because we enabled the setting to automatically create environment variables for new data sources, Power Apps is going to create 2 environment variables.
An environment variable for the SharePoint Site that houses the list
An environment variable for the SharePoint List itself.
NOTE: If you’ve gone through this process before in this environment with the automatic environment variable creation setting toggled on, Power Apps will recognize that there is already an environment variable for the site and ask if you’d like to use the one that already exists or if you want it to create a new one. Otherwise, Power Apps will connect the site and list and you’ll get a banner at the top of the screen that environment variables were created.
At this point, add a gallery (Gallery1) to the app and set its data source to the SharePoint List.
Add a form (Form1) and set its data source to the SharePoint list and its Item property to Gallery1.Selected.
Add a button (Button1) and set its OnSelect property to SubmitForm(Form1).
Save your app and Publish it.
Now Leave the app by clicking the Back button on the Power Apps toolbar and then clicking Leave in the dialog box.
When you load back to the Solution screen, you’ll see you now have 3 elements inside your solution: the app and 2 Environment Variables.
Add a flow to your solution (12:25)
In your solution view, click the + New button and hover over Automation, then hover over Cloud flow, and click Instant.
Give the flow a descriptive name and choose Manually trigger a flow. Then click Create.
Click +New step.
Search for and click the SharePoint Get items action.
In the Get items action step, we would normally click the dropdown arrow and find our SharePoint site that houses the List we created, but we want to take advantage of our environment variables. So instead, click the dropdown arrow next to the box for Site Address and scroll to the bottom where it says Enter custom value and click that.
At the top of your dynamic content box, you’ll find all your Environment variables. Click on the environment variable for the Site containing our List.
For the List Name, do the same thing, click the dropdown arrow and choose Enter custom value and select the Environment Variable for the List we created.
Click + New step and search for then click Compose.
Click in the Inputs box and in the Dynamic content box, click Expression.
For the expression, type: length() and put your cursor inside the parentheses. Then click back on the Dynamic content tab and choose the value property from the Get items step. Now click OK.
Save your flow and do a Test run of it. The results of the Compose step should be 3, or the number of items you added to the site.
Click the Back arrow in the top-left of the flow designer to go back to your Solution screen.
Now you’ll notice your solution has 5 elements in it. There are the 3 that were there before (the app and 2 environment variables). Then there’s the flow we just added. And finally there is a Connection Reference object for our flow to recognize there is a connection to SharePoint.
If your solution lacks that Connection Reference element, click the 3 dots next to your flow, hover over Advanced and click Add required objects.
Prepare the environment variables for transport (16:30)
So our environment variables are connected and functional in this environment, and we’re now ready to move the solution to a new environment, right? Wrong. Before we can move the solution, we need to make the environment variables ready to work in the new environment by removing their default values.
So click on the environment variable for your SharePoint List.
In the pane that loads, find the setting for “Current list”. It should currently be showing the name of your SharePoint list. Click the 3 dots next to this dropdown and choose Remove from this solution. This step removes the mapping of the environment variable to the specific list name. The reason we need to remove this is so that we will be required to specify the new mapping during the import of our solution in the new environment.
Click Show default value and verify Default list value has nothing in the box.
As long as Current list value and Default list value have nothing showing, we can click save because this variable is ready to move.
Now let’s do the variable for the Site. So click on that object in your solution.
In the pane on the right, next to the dropdown for the Current site value, click the 3 dots and choose Remove from this solution.
Double check that Default site value also displays nothing and now this variable is prepared for the move as well.
Export the solution (18:09)
On the Solution screen, click the Overview button in the left-side navigation.
Click the Export button in the top bar above the Solution overview.
You will be presented with some options to run before your export your solution. While it is not a requirement, Shane prefers to click Publish each time, just to satisfy himself that there are no unpublished changes. This is not a requirement, but is a good safety tip.
Also not a requirement is the option to Run the solution checker to verify there are no errors or other issues that might cause your Solution to have problems. Run this if you want, otherwise click Next.
On the next pane, you can set the version number, or just accept the auto-incremented number. Then you need to choose between Managed or Unmanaged for your Solution type.
So what do these solution types mean?
Essentially, Managed means the solution can only be edited from this environment. Whichever environment or tenant that we export this solution to will only be able to run the apps and flows in the solution, they won’t be able to modify them. A great example for when Managed is useful is if you’re currently in your Dev environment and you will be exporting the solution to a Test or Production environment.
On the flipside, Unmanaged means the apps and flows in the solution can be edited from the environment or tenant that we import this solution into. A great example for when Unmanaged is useful is if you’re wanting to provide a copy of your app/flow to a different environment/tenant and they need the ability on that end to modify or peek under the hood of those elements.
For our purposes, we’re going to choose Unmanaged. Then click Export.
The wheel will spin and then the pane will disappear, and it will look like nothing is happening except right above the Overview, a bar will show up that says “Currently exporting solution”. Once that banner turns green, click the Download button on the right side of it to download the package file for your solution.
Import solution into new environment/tenant (21:46)
Now switch to the destination environment. This can be done by clicking the Environment switcher in the top-right corner of the Power Apps screen and choosing a different environment or by logging out and logging in to a different tenant. Regardless of which route you’re taking, once you’re into the new environment, click on Solutions in the left-hand navigation bar.
Before we can import the solution, we need to create a copy of the SharePoint list for this version of the solution to use as a data source, because remember, the original SharePoint list doesn’t get included in the Solution, the environment variable does.
Open a new tab and go to SharePoint for the destination tenant.
Create a new list.
The list can be named anything you want.
The primary concern here is that the list contains the same column structure as the original list.
Add some sample data to the list. For sanity’s sake, use different values and even a different number of items than you created on the original list, just so you can easily see if you’re talking to the correct list or not.
Once this has been created, we’re ready to jump back to our tab where we’re sitting at the Solutions view on the new tenant/environment.
Click Import solution
Click Browse.
Find the solution file you downloaded earlier and click it then click Open.
Click Next.
Click Next on the Import overview screen.
On the Connections screen, the importer is going to ask you to map the SharePoint connection reference to a SharePoint connection on the new tenant/environment. If you don’t have a connection already established in this environment, you’ll need to use the dropdown to create a new one. If you already have a connection, choose that and click Next.
If you have trouble using an existing connection, make sure the token on that connection hasn’t timed out. You might need to refresh that connection’s authentication before it will work properly with the solution.
The next screen will show the Environment variables, and it will state that 1 or 2 of them needs updated. If you already had an environment variable for the site, it will not be flagged as needing updated.
For the Environment variables, choose the SharePoint site for this tenant/environment from the drop-down that houses the SharePoint list you created in step 4 of this section.
Then for the List variable, choose the list you created in step 4 of this section.
Click Import
The banner at the top of the Solutions view will read “Currently importing solution” Wait for this banner to turn green indicating a successful import.
You can now drill into the imported solution and see all the components.
If you open the app, you’ll see that the data has seamlessly switched to that from the new list.
Note: at the time of this recording, if you go to the Data view in Power Apps Studio, it will show your SharePoint connection to the original list, and if you click the 3 dots and choose to Edit Data, it takes you to the original SharePoint list. This issue has been reported to Microsoft.
If you go back to the solutions view and then open the flow, you can run a test without changing anything and you’ll see that it is in fact looking at the new list.
Deleting part or all of the solution (29:21)
There is a little bit of nuance to deleting solutions from environments. If you go to the main Solutions view and select the solution and click delete, you will receive a warning indicating that when you delete the solution, you are only deleting the package that contains all the elements of the solution. Those elements (the app, flow, variables, etc.) will still remain in your environment. To truly purge everything that was imported, you need to click into the solution to see the list of elements, and from there select each element, click Remove and choose “Delete from environment”. Then once those have been removed, you can delete the solution package itself.
Additional learning:
Power Platform University
Are you looking for full, personalized Power Platform training? Do you want a mentor to help guide you on your journey? Do you prefer real world content instead of academic concepts? Then Power Platform University from PowerApps911 is for you.
Learn more here.
Comments