Get Dynamics/CDS Base URL in Flow To Generate Links To Record

When sending emails or approvals in flow it can be helpful to also include a link to the record which is being referenced.  In order to send those links though we need the environment URL of the Dynamics/CDS environment.  This article shows an example of how to get the base URL for the environment and how to build a link based upon it. 

This will be demonstrated within a Flow created for the App In A Day Workshop. In this Flow we are attempting to get an approval when a Device Order entity record is created from our Canvas App.  The Approval step allows us to include a link to the item and we will also be sending out emails to the requester based upon the Approval outcome which will include the link.

The first Action we need to add to our existing workflow is the CDS Get record step.  Why do we need this step?  Well unfortunately the Output that is provided from the Flow Trigger of when a record is created does not include the URL to the record.  Instead we need also include the Get record step which will include the record URL in it's Output.

Next we need to parse the Output of the returned record and get the base URL of the dynamics environment.  We can do this by adding an Initialize variable Action to our flow.  As you can see below we are first creating an expression that will grab the URL from the field within the body of the output.  The field is the OData URL of the record so we cannot just sent the user that, instead we parse that URL to get the base environment portion.  After you parse out the environment UR  you can then add on the rest that will allow a user to actually view the record in Dynamics.

Expression to Parse URL (Note: Replace Get_Current_Record with the name of the Get record action you created earlier): first(split(outputs('Get_Current_Record')?['body']?[''],'/api/'))

So how did we determine how to parse the URL?  You can view the output of the Get record activity by view either running the Flow in Test mode or you can view a historical run of the Flow where the Get record activity has already been added.  From here we can view the JSON output which allows us to determine the parsing.

Finally we can utilize the Record URL variable we have initialized within the other action in our Flow.


Popular posts from this blog

Add User As Local Administrator On Domain Controller

Calling Dataverse Web API in PowerShell using Client Credentials

Windows Server 2008R2 VMs Shut Down After 1 to 2 Hours