Power Automate - Generate a Link to a Record

Learn how to get the base URL of the current environment in which the flow is triggered.

Power Automate - Generate a Link to a Record

Intro

I had a colleague reach out recently asking if there was an easy way to create a link to a record in a Power Automate flow similar to how we can in classic workflows.

The answer is - absolutely.

But what about environments, do we have to modify the flow for each environment? Do we need environment variables?

Nope!

Follow along to check out the solution.

The Solution

uriHost to the rescue!

Crafting the link isn't as easy as it is in classic workflows, but it isn't all that difficult either.

First thing is first - we need to learn the format to build out the URL. Open any model-driven app that has access to the record you wish to work with.

In this case, I am going to use an Account.

In my case, the URL is as such:

https://orgname.crm.dynamics.com/main.aspx?appid=67546248-8bdb-ef11-a731-002248090685&pagetype=entityrecord&etn=account&id=fb9ba5e5-b1de-ef11-8eea-000d3a33e488

A couple things need to be made dynamic here

  1. the base url (orgname.crm.dynamics.com)
  2. the id of the record you wish to navigate to

The appid can be ignored - the record will simply open in the last model-driven app the end user had open.

If you would like to dictate which model-driven app is opened, you can query the Model-driven Apps table to get the appmoduleid

In this simple example, we have our trigger and a Compose action that builds the URL.

We need to get the OData metadata of the account record that we wish to open. The trigger action doesn't supply this for us. So, let's add a Get a Row By ID action and ensure the Return Full Metadata parameter is set to Yes so we can get the OData metadata returned to us.

Take a look at the following expression that we can use in our Compose action:

https://uriHost(outputs('get_account_odata_metadata')?['body/@odata.id'])/main.aspx?pagetype=entityrecord&etn=account&id=triggerOutputs()?['body/accountid']

uriHost accepts the odata.id parameter from the OData metadata we retrieved in the prior step. This expression gets the base URL - allowing you to use this across environments without having to make any changes.

Simply pass in the accountid of the record you would like to navigate to by using the Dynamic Content.

The finished product should look something like this:

The result of the Compose action is as follows:

Opening this link takes us to the record we expect!

Wrap-Up

While not as straight forward as adding a link to a record using classic workflows, this is still reasonably simple to achieve in Power Automate.