[Quick Tip] Get SubGrid View Id using Primary Control or Selected Control for Ribbon button’s enable rule in Dynamics 365 CRM.

Amit Prajapati
2 min readMar 28, 2021

Use case: I have two entity Awards and Awards category. We have SubGrid on the Awards entity form for Category with Custom Ribbon button. We want to have the button should be visible on specific view only and below are steps to do so.

Step 1: Configure the Ribbon Button

Create a Ribbon Button, create a command and enable rule. Added enable to Command and command to ribbon button. To enable rule, create a custom rule and pass the JavaScript and parameter.

RIbbon Workbench Dashboard

Step 2: Get View id based on the CRM parameter:

Now, Get Subgrid view id by passing the CRM parameter in the custom rule.

When CRM parameter is Primary Control

When CRM parameter is Selected Control

Step 3: Write script for Enable Rule for Custom Ribbon Button.

We will write a script that will enable or disable the Ribbon based on the view ID using the above code based on the passed parameter.


I have written the enable rule that Button should be visible only on the Active Award Category view:

Change Award button is visible when the view is “Active Award Categories”
Change Award button is hidden when the view is not “Active Award Categories”
Result View of Current View that we get from the Controls in Web Browser Console App

Full Code:



Amit Prajapati

I am Technical Consultant from Mumbai, India. I like to contribute my knowledge to the community and good social cause.