Get displayed ViewId on click of ribbon button in Home Page Grid in Dynamics365/ PowerApps. Explore the hidden gem–Xrm.Navigation.getPageContext()

This is a requirement I received few years back. And that time I said it is unsupported and hence not possible. And today again I got this requirement and guess what I was about to say the same thing when I thought – “The API now is much more rich. There may be something in there.”

And guess what, after elaborate search I found something which is purely a hidden gem – Xrm.Utility.getPageContext()

Now I have a ribbon button on my Account home page grid and I have registered an action on the button. Below is the function that is invoked when the button is clicked.

function ribbonClick() {
    var pageContext = Xrm.Utility.getPageContext();
    var input = pageContext.input;
    var entityType = input.entityName;
    var viewId = input.viewId;
    var pageType = input.pageType;
    console.log(“Entity: “, entityType, ” ViewId: “, viewId, ” PageType: “, pageType);
}

Awesome isn’t it. There is so much you can do now. Below is the output for the console.

Entity:  contact  ViewId:  {00000000-0000-0000-00AA-000010001004}  PageType:  entitylist

Next time someone asks you to get the viewid, you have Xrm.Utility.getPageContext() to bail you out.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Notes Manager (https://debajmecrm.com/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)


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