Disable Sub Grid record buttons in ribbon based on Parent record’s value in CRM 2011.


Recently we had a requirement to disable Add New and Edit button of a sub grid record based on parent record’s attribute value.

For this we first need to add a new EnableRule and pass the id of the parent record to a custom function that will use this value to get value of the form and pass true and false accordingly.

FirstPrimaryItemId CRMParameter will pass the id of the parent record.

<EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule">
 <CustomRule FunctionName="DisableButton" Library="$webresource:new_myScript" Default="true">
 <CrmParameter Value="FirstPrimaryItemId" />

Adding this EnableRule to existing CommandDefinitions

 <CustomActions />
 <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
 <CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard">
 <EnableRule Id="Mscrm.AppendToPrimary" />
 <EnableRule Id="Mscrm.EntityFormIsEnabled" />
 <EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule" />
 <DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
 <DisplayRule Id="Mscrm.AppendToPrimary" />
 <DisplayRule Id="Mscrm.CreateSelectedEntityPermission" />
 <DisplayRule Id="Mscrm.AppendSelected" />
 <DisplayRule Id="Mscrm.HideAddNewForChildEntities" />
 <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
 <CrmParameter Value="SelectedEntityTypeCode" />
 <CrmParameter Value="PrimaryEntityTypeCode" />
 <CrmParameter Value="FirstPrimaryItemId" />
 <CrmParameter Value="PrimaryControl" />
 <CommandDefinition Id="Mscrm.EditSelectedRecord">
 <EnableRule Id="Mscrm.CheckBulkEditSupportForEntity" />
 <EnableRule Id="Mscrm.VisualizationPaneNotMaximized" />
 <EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule" />
 <DisplayRule Id="Mscrm.BulkEditPrivilege" />
 <DisplayRule Id="Mscrm.WriteSelectedEntityPermission" />
 <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.bulkEdit" Library="/_static/_common/scripts/RibbonActions.js">
 <CrmParameter Value="SelectedControl" />
 <CrmParameter Value="SelectedControlSelectedItemReferences" />
 <CrmParameter Value="SelectedEntityTypeCode" />
 <TabDisplayRules />
 <DisplayRule Id="Mscrm.AppendSelected">
 <EntityPrivilegeRule PrivilegeType="Append" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
 <DisplayRule Id="Mscrm.AppendToPrimary">
 <EntityPrivilegeRule PrivilegeType="AppendTo" PrivilegeDepth="Basic" AppliesTo="PrimaryEntity" />
 <DisplayRule Id="Mscrm.BulkEditPrivilege">
 <MiscellaneousPrivilegeRule PrivilegeName="BulkEdit" />
 <DisplayRule Id="Mscrm.CreateSelectedEntityPermission">
 <EntityPrivilegeRule PrivilegeType="Create" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
 <DisplayRule Id="Mscrm.HideAddNewForChildEntities">
 <EntityPropertyRule AppliesTo="SelectedEntity" PropertyName="IsChildEntity" PropertyValue="false" />
 <RelationshipTypeRule AppliesTo="SelectedEntity" AllowCustomRelationship="false" />
 <DisplayRule Id="Mscrm.ShowForOneToManyGrids">
 <RelationshipTypeRule AppliesTo="SelectedEntity" RelationshipType="OneToMany" />
 <DisplayRule Id="Mscrm.WriteSelectedEntityPermission">
 <EntityPrivilegeRule PrivilegeType="Write" PrivilegeDepth="Basic" AppliesTo="SelectedEntity" />
 <EnableRule Id="new.new_fcm_child.EnableRule2.EnableRule">
 <CustomRule FunctionName="DisableButton" Library="$webresource:new_Service_Request_Script" Default="true">
 <CrmParameter Value="FirstPrimaryItemId" />
 <EnableRule Id="Mscrm.AppendToPrimary">
 <RecordPrivilegeRule PrivilegeType="AppendTo" AppliesTo="PrimaryEntity" />
 <EnableRule Id="Mscrm.CheckBulkEditSupportForEntity">
 <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" Maximum="1" />
 <SelectionCountRule AppliesTo="SelectedEntity" Minimum="2" />
 <CustomRule FunctionName="Mscrm.RibbonActions.isBulkEditEnabledForEntity" Library="/_static/_common/scripts/RibbonActions.js">
 <CrmParameter Value="SelectedEntityTypeCode" />
 <EnableRule Id="Mscrm.EntityFormIsEnabled">
 <FormStateRule State="Disabled" InvertResult="true" />
 <EnableRule Id="Mscrm.VisualizationPaneNotMaximized">
 <CustomRule FunctionName="Mscrm.RibbonActions.disableButtonsWhenChartMaximized" Library="/_static/_common/scripts/RibbonActions.js">
 <CrmParameter Value="SelectedControl" />
 <LocLabels />

The JavaScript code

// function to disable related record
 function DisableButton(id) {

 //CRM Server Url:
 var result = true;
 var serverUrl = Xrm.Page.context.getServerUrl();

// OData Call to get the data
 var ServiceRequestQuery = "new_CustomEntitySet?$select=attr1,attr2&$filter=attrId eq guid'" + id + "'";
 var ServiceRequestUrl = serverUrl + "/XRMServices/2011/OrganizationData.svc/" + ServiceRequestQuery;
 // make synchronous call
 var ServiceRequest= syncODataCall(ServiceRequestUrl);
 // get the option set value
 if (ServiceRequest[0].attr1 != null && ServiceRequest[0].attr2 != null) {
 var attr1Value = ServiceRequest[0].attr1.Value;
 var attr2Value = ServiceRequest[0].attr2 .Value;

if (attr1Value != "863600004" && attr2Value == "279640002") {
 result = false;
 else {
 result = true;
 return result;

// function to make synchronous oData call
 function syncODataCall(odataSelect) {
 var request = new XMLHttpRequest();
 request.open("GET", odataSelect, false);
 request.setRequestHeader("Accept", "application/json");
 request.setRequestHeader("Content-Type", "application/json; charset=utf-8");
 var objJQuery = JSON.parse(request.responseText);
 return objJQuery.d.results;

Hope it helps


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “Disable Sub Grid record buttons in ribbon based on Parent record’s value in CRM 2011.”

  1. We are trying to open the Quick create form (instead of the main form) when user click on the + button from the subgrid . unfortunately it always opens the main form.

    Can you please suggest what are we doing wrong.

    Since the + button was not available when we created the relations, we added the button using ribbon workbench , and gave the command as “Mscrm.AddNewRecordFromSubGridStandard &

    Can you please suggest


Please share your thoughts

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

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog & Website of Paul Andrew

Technical Leadership Centred Around the Microsoft Data Platform

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform


Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions


Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM


Mail to crmtipsbyprm@gmail.com for queries and suggestions


Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM


Step into the world of a Dynamics 365 Consultant

Dianamics PCF Lady

Diana & Dynamics 365 & Power Platform

Sara Lagerquist

No Code Customization Concepts

%d bloggers like this: