So recently I blogged about the capability to interact with other Dataverse environments than the one the solution is currently being run in, in both Power Apps and Power Automate! Check out those posts below if you haven’t already read them before continuing here to gain the context…
What’s next?
So, in this post, I’ll be showing you how to develop further on the capabilities above with environment variables to make this functionality ALM supported using solutions in Power Platform. Let me know in the comments what you’ll use this functionality for, or if you’ve got any questions on the topic! 🚀
Creating a Dataverse environment variable
So first, let’s take a look at creating an environment variable which stores a reference to an environment in our tenant. I’m going to create an environment variable in a solution and set the data type to ‘Data source’. Then I’ll select ‘Microsoft Dataverse’ as the connector.
Now by selecting plus on the new environment value for either the current environment value or default, we can add an environment.
Accounts in two environments
Okay so let’s take a look at my accounts table in two environments. In one environment, Development, I’ve got these 2 accounts…
Then in a second environment, being my test environment, I’ve got these accounts…
So, I’m going to leave my environment variable value set to Development for now, and we’ll look at referencing that in Power Apps and Power Automate, then we’ll also look at what happens when I change the variable to another environment (Test).
Referencing in Power Apps
Okay so first, let’s look at Power Apps. To add a Dataverse table from the environment we want by referencing that environment through a set environment variable we need to start by adding data. Then instead of selecting a table, select ‘Change environment’.
Then, instead of selecting an environment which will hard code which environment this app looks to for data, select Advanced and choose an environment variable to pull an environment reference from.
Then the environment tables will show and you can select a table to use data from there…
So I’m going to add a gallery to my screen which shows Accounts for the environment which my environment variable currently holds. At the moment it’s set to Development so as you can see I’ve got my development environment accounts showing…
Now let’s see what happens with the environment variable set to the test environment…
Awesome! As you can see, despite being in the development environment still, my app is showing my test data because the environment variable now references that environment.
Referencing in Power Automate
Now let’s take a look at how to reference these environment variables in Power Automate. I’ve got a flow in a solution here and I’ve got the action for listing rows from a selected environment.
Now to reference the environment value from an environment variable, all we have to do is populate the environment parameter with a custom value which will be our environment variable dynamic content.
Now running the flow still set in my test environment… let’s see what I get back…
As you can see, there’s my Low Code Lewis account which I had in my test environment. And now flicking the environment variable value back to Development…
There’s my accounts from my development environment! Awesome, and so simple!
Did you like this content? 💖
Did you like this content? Check out some of the other posts on my blog, and if you like those too, be sure to subscribe to get my posts directly in your inbox for free!
Subscribe