How to get GUID of selected view in Dynamics 365/ Model driven apps home page grid

Welcome back to another blog post on Dynamics 365/ Model driven app and today I am going to discuss about a unique requirement. Get the GUID of selected view of a table in Model driven apps entity list/ grid. Basically get the GUID of ‘My Active Contacts’ view.

Get Selected View Id in Home page grid of Model driven apps/ dynamics 365

In my case, the client wanted it to get it on click of ribbon button. What they will do post getting the GUID of the view is different requirement altogether and I am not going to dive into that. For this blog post, I will try to do the same i.e get the GUID of the selected view on click of a ribbon button.

I have created a custom button on the Contact grid – Get View ID.

Get Selected View Id in Home page grid of Model driven apps/ dynamics 365

On click of that ribbon button, I am executing the below code. getViewId is the function which I am invoking on click of the custom ribbon button.

function getViewId(formContext) {
   debugger;
   var pageContext = Xrm.Utility.getPageContext();

   var input = pageContext.input;
   var selectedViewId = input.viewId;

   console.log("Selected View", selectedViewId);
}

If you carefully look at the code above, the most important function is – Xrm.Utility.getPageContext(). Trust me, it’s quite unknown to lot of developers and honestly to me as well till I got this requirement.

Below is the entire stuff in action.

Hope this helped!

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading