After five years, it’s time to update my post “Get CRM URL in Power Automate“…
Cases where you might need to get the Environment URL
- When you ‘Relate’ or ‘Unrelate’ two records with the Dataverse action
- For generating a direct link to a specific record for activities or other records
- If your Flow logic has different branches for the production environment then for the others. For example in approvals processes, for email send outs or or integrations with third-party systems.
Options for retrieving Environment URLs in your Power Automate Flows
1. Environment Variable
Environment Variables are configurable values used within solutions. They follow the KeyValue principle, where the Key is fix defined and the Value can vary between the different environments. The value gets set during the deployment of the containing solution.
Here are two links where you can find informations about Environment Variables and how to use them in Power Automate
- Environment variables for Power Platform overview
- Use environment variables in Power Automate solution cloud flows
2. Previously used Dataverse Action
If you already use a Dataverse Action (not a Dataverse Trigger) in your Power Automate Flow, it might be worth checking out it’s output. Maybe you find there the Environment URL.
It doesn’t play a role for us if the ULR ends behind the domain (.com), or if it has paths (.com/path/subpath) and / or parameters (.com?ad=YourAdPlacement) behind it.
The following expression ignorantes all elements behind the domain and returns a clean URL.
join(take(split(outputs('YOUR_AD_PLACEMENT'), '/'), 3), '/')
My preference
As most of my Power Automate Flows operate in Dataverse environment, there is mostly already a Dataverse action where I can pick the URL from. There is also no chance for a human error during setup, compared to Environment Variables.