web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Connection to differen...
Power Apps
Suggested Answer

Connection to different Business Central environment from different PowerApps environments

(0) ShareShare
ReportReport
Posted on by 8
Hello!
 
I have made a PowerApp in a solution in PowerApp, and I have added a couple of galleries and forms to the app that is using the Business Central connection.
 
I have an environment for development, one for testing, and one for production.
 
In the app interface, I just select the connection I want to use, then I select the Business Central environment and company, and lastly I select the table I want to connect to.
This is all working very well in Dev, but it feels very hard-wired, because the dataset of the connection in my PowerApp is connected to a sandbox and company, and I am not allowed to change that without removing it and adding a new connection. So I was wondering how I can add a connection to a Business Central table in a specific BC sandbox in Dev, and then connect to a different BC sandbox in my test environment, and lastly to the Production environment in BC in my production environment in PowerApps.
 
I have come across Connection References in the solution, but I am not sure if that's what I want to use. 
 
I also want to deploy the solution via a pipeline, but when doing that, I am not prompted with any message asking me which Business Central environment I want to connect to.
 
How do I set the solution up in this way, that I can use different BC environment for different PowerApps environments?
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,493 Super User 2025 Season 2 on at
    Hi @Hagru
     
    Yes, you want to use Environment Variables. That is what they are for.
     
    When you build in Dev, make sure the setting for Automatically create Environment Variables is turned on. Now, there is another action to perform which I will explain and then continue.
     
    When you normally add something to a solution, and you have your own Publisher, let's pretend it has a prefix of hagru_ , any new items will have that prefix. however, when you use the setting to auto-create Environment Variables for Connections you create IN a Power App (via the Data Tab), it will NOT be this, it will be _new as if its part of the default solution(because it is), and not automatically added to your Solution.
     
    So after you add all your data (which btw, if you did NOT have this setting on initially you will have to turn on the setting. Save. Publish.  CTRL F5. Come back in, remove the data, save. CTRL F5 and re-add them (its to be safe the best process), it will create these Environment variables, you will need to go to your Solution, go to Add Existing, more.. Environment Variables and then select all the ones that got created to make them part of your solution.
     
    Ok, now that they are there.
     
    There are 2 settings for them.
    1) that represents what the value is IN this environment
    2) the default value
     
    When you Import a Solution that has environment variables that act as Connections, it will prompt you to Select Existing Connections that point to your data in that environment, or create new ones, which will automatically point to the new environment data when you sign in and create the connection during import.
     
    now the environment variables Value will be set to a Connection to data in that environment
     
    That is what you want. What you are doing you definitely do not want to do as its not good ALM practices.
     

    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    Thank you!
    Sincerely, Michael Gernaey
  • Hagru Profile Picture
    8 on at
     
    I had a feeling Environment Variables was the way to go, but I didn't quite know how to actually use them with the connections to Business Central. So thank you very much for the reply and detailed answer!
     
    I did however come across an issue. The app was already in a solution with my own publisher, it had the connections I wanted, and I had not turned on the setting "Automatically create environment variables when adding data sources". So I went into the app through the solution, turned on the setting, saved, published and refreshed and confirmed that the setting was on. Then I removed the connections I had, saved, refreshed, and added them back in. Everything looked exactly like it had done before, I went into the data tab, added connection, chose the BC environment and company, and then the tables, and added them back in. There were no new prompts or anything different at all.
     
    Then I saved, published and went back out of the app, and in my solution I pressed "Add existing" > More > Environment Variable.
     
    However, there were no new environment variables to add. The list shows 5 msdyn_ variables, but none for my Business Central connections. I also checked in the Default Solution, and there were only the same 5 environment variables there as well.
     
    Thinking it could be an issue with the app itself, I tried adding a brand new app to the solution, making sure the setting is enabled once again, and adding the connections. Still nothing in my "Add existing" list of environment variables.
     
    I also tried completely removing the connection to Business Central, going into my app and re-adding it, but there is still no new environment variables created.
     
    Am I missing something?
  • Michael E. Gernaey Profile Picture
    53,493 Super User 2025 Season 2 on at
    Hi @Hagru
     
    I am super sorry for the delay.
     
    When you use the option to auto-create them, and this part is annoying, it will always start with new_ because the default (and yes they will go to the default solution also), will always be new_
     
    Its annoying and you cannot fix it, unless you manually go in and create the Connection Environment Variables Manually.
     
     Unless you do not have permission to see them, that is possible, but truly they should be there. I tried it and it worked for me.
  • Hagru Profile Picture
    8 on at
     
    No worries, I appreciate you taking the time to reply!
     
    It could be a permission issue in that case. I am sitting in a customer tenant, but my user should have admin privileges, so I am not sure what could be missing. 
     
    I followed your recipe a bunch of times, trying all kinds of different things, but no matter what I did and where I looked, I was unable to find the environment variables that should've been created when I added the datasource in my PowerApp. I understood that they would have the new_ prefix, but they did not show up in my list of environment variables that I could add, unfortunately.
     
    I gave up on the direct connections and resorted to PowerAutomate flows with environment variables, but I would've loved to use the direct connections, as they make life so much easier. I was debating if I should just stick with the connections and manually change them to the right environment each time I deployed, but I figured that would create an issue eventually where I forget one.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard