Approval action add link to model driven record

Shows an animated gif where inside the MS Teams approval center we click the record URL and the Model-driven App is opened for us.

When you are deciding if you want to approve an action, you probably want more information then a description. Luckily we can add a link to our Approval request! This is a follow up on my previous post where I showed how to trigger an Approval inside a Business Process Flow. In this blogpost I will show you how to generate a link to the record we are working on.

This blog is part of a series about guiding users and teams through their work. This post is about Approval Flows inside Business Process Flows. Click here for an overview of all related post regarding Approvals inside your Business Process Flow. I also added a sample solution you can import in your own development environment so you can see the entire concept in action!

Keeping people in their flow of work by utilizing Asynchronous work or asynchronous processes is one of the key benefits for Business Process Flows. I have written down my thoughts on this subject here. Find out what asynchronous work is, how Business Process Flow can help and more advanced scenario’s.

The Item link property

As mentioned in the introduction, it is very convenient to be able to navigate to a record when you want to give approval. As a manager you can view all related information and see if everything is in place.

Shows the Power Automate Action Start and Wait an Approval. With a highlight on the properties Item Link and Item Link Description to show what we need to fill in for a link to appear in the Approval.Item Link in Approval Action

To do so we can fill in the Item link and item link description of the Approval action “Start and wait for an approval”. The Item link property is for the URL and the description is the text that will be shown for the hyperlink.

Shows an extract of an Approval e-mail where we can see the Link the item link property generatesEmail with an Approval Link

However we do not know the record link inside the Approval flow. We will need a few tricks to generate the link to the Model-driven App record. It is also important to keep in mind that this Flow needs to work across multiple environments as we are currently working in a development environment. When I transfer our solution to the test or production environment I do not want to manually change the URL

Examine the Record Url

Let us first take a look at the URL of a model-driven app record as we want to replicate this in our Item Link.

Highlights the URL in a browser which has a record opened in the Model-driven AppRecord URL in the Model-driven App
https://orgff248fa5.crm4.dynamics.com/main.aspx?appid=30bf5a45-388e-ec11-b400-000d3a448670&pagetype=entityrecord&etn=bdenb_case&id=ee2b65f2-b4d8-4b23-ae8f-4138bf0f6fe9

There are a couple of properties which are dynamic and which we need to change:

  1. “orgff248fa5”. The environment name of your Power Platform. If you are not working on a developer environment you probably have set this to a more readable name 
  2. “appid”. The Model-drive application Id which we want to open. If there is only 1 application in the environment you could skip this. However I recommend to set this as well, it’s only 1 extra step in your flow.
  3. “id”. The Id of the record.

Grab the current URL from a Dataverse action

To get the environment name we are working in, we can use a little trick. This trick will also give us the base part of the link to the model-driven app we eventually need. In the outputs of the update action we get a few URLs we can use. For example the OData ID we see below. This is actually the direct API link to the record we just updated.

Shows the OData Id Outputs property of the update action.OData Id property

To use this URL in the Link we build op later we have to put it in the Compose action. This will change it from an object to a string.

Shows the Power Automate Compose action where we add the OData Id property to use in the Uri Host in a later step.Compose OData Id

When we build up the Link we will use the function function “uriHost”. This function will give us the base part of the URL. In our example this will give us: “orgff248fa5.crm4.dynamics.com” and thus gives us the Environment name too!

Retrieve the App Id stored in Dataverse

Nowadays we build multiple Apps on the same environment. Apps specific for a certain use case or role. This however makes it required to add the AppId in the Link we want to build up. Luckily all the Model-driven Apps are stored in Dataverse in the table Model-driven Apps. So we can retrieve them using a List Item action:

Shows the Power Automate Dataverse Action List Records. This is used to retrieve the AppModuleId from the table Model-driven Apps. Filtered on the "uniquename eq 'bdenb_CaseManagement'".Get Model-driven App Id using the list action

We only need the appmoduleid as this contains the Id we need. So we only select that column. I actually found out about this table by a blogpost from Sara Lagerquist. It contains the following quote:

“The List Record action is not a buffet, it’s an a la carte menu. You do not order the whole menu of food and then pick an choose what to eat. That would be too expensive. You decide before hand what to order and make sure you consume it all.”

Sara Lagerquist

Which of course is good practice for performance of your flow. The filter uses the “Name” and not the “Display Name” of the app:

uniquename eq 'bdenb_CaseManagement'

Building the Url for the Item Link

Now that we have all the necessary properties we can build up the Url for the Item Link. For readability I like to use a specific Compose action for the URL. We start of the url with “Https://”

After which we use the function uriHost with the parameter the OData Id we put in a compose. This will give us the base part of the url. We follow up with the string “/main.aspx?appid=”. Main.aspx is the default page the Model-driven apps live in. After the question mark of the Url we can build up the parameters. This first one is the AppId.

Shows the Power Automate Compose action where the record URL is created.Create the record URL

We add the AppId dynamically from the List Items action. This will of course return only 1 record. Thus we can safely use the First function.

first(outputs('Get_Model-Driven_App_Id')?['body/value'])?['appmoduleid']

Now we add “&pagetype=entityrecord&etn=bdenb_case&id=”. This will tell the App that we want to navigate to a specific record of the table “bdenb_case”, which is my own case table. After the id we will use the record id from the “Update record” action.

This will now give us the following code in the component action:

https://@{uriHost(outputs('Compose_the_Odata_link_to_grab_the_uri_host_later'))}/main.aspx?appid=@{first(outputs('Get_Model-Driven_App_Id')?['body/value'])?['appmoduleid']}&pagetype=entityrecord&etn=bdenb_case&id=@{outputs('Update_the_case_status_and_approver_comment')?['body/bdenb_caseid']}

Now for the final result

We are now nearly done! Add the output of the compose action to the “Item link” property of the Approval action. And we add a “Item link description” for the text of the Url. I added the “Name” of the record of the approval for clarification.

Shows the Power Automate Approval Action with all the properties filled in.Complete Approval Action

Now that we are done let me show you the result in the Microsoft Teams Approval center:

Shows an animated gif where inside the MS Teams approval center we click the record URL and the Model-driven App is opened for us.Approval Link in action

Adding the Item link puts the finishing touch on our Approval request. This ensures easy access of the information required by the Approver. With the technique I described in this post we can ensure this works in ALM scenario’s as well.

posted @ 2023-04-07 15:13  Javi  阅读(45)  评论(0编辑  收藏  举报