“I have an old Power Automate flow with fixed connections, what’s the fastest way to replace all of them with env. variables?”
As already mentioned in previous articles, when you build a flow you should build it as a Solution. But it’s probably not something you do from the beginning. When you start with Power Automate, you probably start by building simple flows. You go to the Power Automate portal and start building, not even knowing about something like a Solution. And then comes a day when you learn about Solutions, and you have a ton of flows without them, with fixed connections…
How do you catch up? What’s the fastest way to replace the fixed flow parts with environment variables, to turn them into proper Solutions?
Replace it in the flow JSON
One of the options is going through all the flows and updating the actions manually. While it’s the most straightforward one, it’s also the most time consuming with a high risk of making a mistake.
A much more efficient approach would be to batch replace it directly in the flow code. In the same way as you can reconnect flows to different lists, you can also replace the fixed connections with environment variables.
Since you’re mapping it from fixed connection to env. variables, you’ll need the env. variable identifiers. Create a new flow where you list all the environment variables in a single action.
Copy / paste the action in a code editor, e.g. Visual Studio Code, to see the variables code.
Next, copy the flow you where you want to replace the connections in the same way. In the ideal case it should be the whole flow (as you already have it in a single Scope to handle errors)…
…and paste it in the code editor.
Replace all fixed sites urls and list ids with the environment variables.
Copy / paste the adjusted flow definition back into the flow. The fixed connection will be replaced with the environment variables.
It might work also in the exported flow
I believe the same approach should work also when you export the flow as a .zip file, similarly to the previous article. Unfortunately, the import seems to be broken at the time of this article so I can’t 100% confirm.
Summary
Even if you started your automation journey without any knowledge about solutions, it’s still not too late to fix it. Since you can access the code of the Power Automate flows, you can quite easily batch replace the fixed connections with env. variables.
Export/copy the flow, paste it in the text editor, and replace all fixed url / list id occurrences with environment variables. Put the flow back in the editor and voila, the flow is using environment variables and is ready to be part of a solution.