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 or reach out to us at

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (

Notes Manager (

Role based views for Dynamics 365 (

Record Cloner for Dynamics 365 (

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s