“All those environment variables make quite a mess when building a Power Automate flow, how can I reduce their number?”
As already said in a previous article, you should create all your flows in Solutions. Not only will it help you to stay organised, but it’ll be much easier to configure or move the flows too. Each solution can include environment variables, a global configuration that can be referenced in the flow or Power Apps. Reconfiguration of the flow is then done through these variables.
Yet if you create too many solutions with too many environment variables it can turn into a mess. Power Automate doesn’t check whether they’re in the solution or not, it’ll show all of them. The more environment variables, the more searching in the dynamic contents.
Is there some way to reduce their amount, to not have a separate env. variable for everything?
Create JSON environment variables
As you probably know by now, Power Automate is based on JSON. All actions in the flow use JSON, all data is stored in a JSON. Why not use JSON also to store data in an environment variable?
JSON gives you the possibility to store the configuration in an object. In the same way you create mapping tables in a flow, you can use them also in the variable.
Create a new Text variable and paste the object with configuration in the variable, e.g.
{
"SPSite": "https://xxx.sharepoint.com/sites/playground",
"SPList": "956e5e0e-bd9e-4a46-9ca5-586c9ed9556c",
"ErrorEmail": "no-reply@tomriha.com",
"RIDPrefix": "REQ"
}
Use JSON environment variable
When using the variable in a flow, it’ll be taken as a text by default.
But you need it as a JSON to select the specific value – apply the json(…) expression on the variable.
Once converted you can select the desired value from the JSON object, e.g.
json(parameters('envVar_JSON (cr309_envVar_JSON)'))?['SPSite']
Summary
While environment variables are a great way to configure your solutions, they can make editing of Power Automate flows quite annoying, hence it might be worth to reduce their number. You don’t have to replace all of them with a JSON, especially if you use them in Power Apps too, but sometimes it’s worth considering also this possibility.