top of page
Search

Power Apps and Automate Solutions and Environment Variables for SharePoint

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)

  1. Go to https://make.powerapps.com

  2. 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…)

  3. In the menu on the left, click on Solutions.

    1. If you don’t see Solutions, you might need to click … More and you’ll find it in there!

  4. On the Solutions screen, click + New solution

  5. 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.

  6. 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.

  7. You can leave everything else at its default setting and click Create.

  8. 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.

  9. Give your app a name and choose its format. For our purposes, we’ll choose a Tablet app. And click Create.

  10. Make sure you save your app.

  11. Once the initial save operation has completed, click Settings.

  12. On the General page, scroll down and find the setting “Automatically create environment variables when adding data sources.” Toggle this setting to ‘On’.

  13. 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.

  14. 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.

  15. 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.)

  16. On the landing page for the SharePoint site, click the Gear icon in the top-right and choose Site contents.

  17. Click + New and choose List and choose Blank list.

  18. Give the list a name and optionally a description, uncheck the “Show in site navigate” box and finally click Create.

    1. 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.

  19. In your list, add 2 columns:

    1. A number column named MyNumber

    2. A choice column named MyChoice using the default options of Choice 1, Choice 2 and Choice 3.

  20. Add some sample data to the list:

    1. Title: Item 1, MyNumber: 1, MyChoice: Choice 1

    2. Title: Item 2, MyNumber: 2, MyChoice: Choice 2

    3. Title: Item 3, MyNumber: 3, MyChoice: Choice 3

  21. Back in your app, click the Data icon in the left-side navigation bar and choose Add Data.

  22. Search for SharePoint and choose the SharePoint result (not the SharePoint Sites Dataverse result).

  23. 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.

  24. Choose the site containing the SharePoint List.

  25. Finally choose the List you created and click Save.

  26. Because we enabled the setting to automatically create environment variables for new data sources, Power Apps is going to create 2 environment variables.

    1. An environment variable for the SharePoint Site that houses the list

    2. An environment variable for the SharePoint List itself.

    3. 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.

  27. At this point, add a gallery (Gallery1) to the app and set its data source to the SharePoint List.

  28. Add a form (Form1) and set its data source to the SharePoint list and its Item property to Gallery1.Selected.

  29. Add a button (Button1) and set its OnSelect property to SubmitForm(Form1).

  30. Save your app and Publish it.

  31. Now Leave the app by clicking the Back button on the Power Apps toolbar and then clicking Leave in the dialog box.

  32. 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)

  1. In your solution view, click the + New button and hover over Automation, then hover over Cloud flow, and click Instant.

  2. Give the flow a descriptive name and choose Manually trigger a flow. Then click Create.

  3. Click +New step.

  4. Search for and click the SharePoint Get items action.

  5. 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.

  6. 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.

  7. 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.

  8. Click + New step and search for then click Compose.

  9. Click in the Inputs box and in the Dynamic content box, click Expression.

  10. 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.

  11. 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.

  12. Click the Back arrow in the top-left of the flow designer to go back to your Solution screen.

  13. 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.

  14. 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.

  1. So click on the environment variable for your SharePoint List.

  2. 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.

    1. Click Show default value and verify Default list value has nothing in the box.

  3. As long as Current list value and Default list value have nothing showing, we can click save because this variable is ready to move.

  4. Now let’s do the variable for the Site. So click on that object in your solution.

  5. 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.

  6. 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)

  1. On the Solution screen, click the Overview button in the left-side navigation.

  2. Click the Export button in the top bar above the Solution overview.

  3. 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.

  4. 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.

  5. 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.

  6. So what do these solution types mean?

    1. 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.

    2. 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.

  7. For our purposes, we’re going to choose Unmanaged. Then click Export.

  8. 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)

  1. 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.

  1. Open a new tab and go to SharePoint for the destination tenant.

  2. Create a new list.

    1. The list can be named anything you want.

    2. The primary concern here is that the list contains the same column structure as the original list.

    3. 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.

    4. 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.

  3. Click Import solution

  4. Click Browse.

  5. Find the solution file you downloaded earlier and click it then click Open.

  6. Click Next.

  7. Click Next on the Import overview screen.

  8. 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.

    1. 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.

  9. 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.

  10. 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.

  11. Then for the List variable, choose the list you created in step 4 of this section.

  12. Click Import

  13. 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.

  14. You can now drill into the imported solution and see all the components.

  15. If you open the app, you’ll see that the data has seamlessly switched to that from the new list.

    1. 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.

  16. 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.

5,099 views0 comments

Comments


bottom of page