title: CRM2011 subgrid button enable rule
body: <p>I have 2 issues. </p>
  
  <p>First issue: Trying to hide OOB button in <strong>subgrid(Ribbon), based on user role(by calling javascript)</strong>. Is it possible?</p>
  
  <p>Second issue:  Hiding OOB button is not possible through "enablerule"javascript, so alternative I tried to disable button by using "enablerule"/javascript. Here is following code which reflects above. Still is NOT working, but for main form Ribbon button, the below code is working.</p>
  
  <p>Can anyone please help me?</p>
  
  <pre><code>&lt;Groups Id="Mscrm.SubGrid.quote.MainTab.Groups"&gt;
                          &lt;Group Id="Mscrm.SubGrid.quote.MainTab.Management" Command="Mscrm.Enabled" Sequence="10" Title="$Resources:Ribbon.HomepageGrid.MainTab.Management" Description="$Resources:Ribbon.HomepageGrid.MainTab.Management" Image32by32Popup="/_imgs/ribbon/newrecord32.png" Template="Mscrm.Templates.Flexible2"&gt;
                            &lt;Controls Id="Mscrm.SubGrid.quote.MainTab.Management.Controls"&gt;
                              &lt;Button Id="Mscrm.SubGrid.quote.NewRecord" ToolTipTitle="$Resources(EntityDisplayName):Ribbon.SubGrid.MainTab.New" ToolTipDescription="$Resources(EntityDisplayName):Ribbon.Tooltip.New" Command="Mscrm.NewRecordFromGrid" Sequence="10" LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.MainTab.New" Image16by16="/_imgs/ribbon/NewRecord_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1" /&gt;
                              &lt;Button Id="Mscrm.SubGrid.quote.AddNewStandard" Command="Mscrm.AddNewRecordFromSubGridStandard" Sequence="20" LabelText="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew" Alt="$Resources(EntityDisplayName):Ribbon.SubGrid.AddNew" Image16by16="/_imgs/ribbon/NewRecord_16.png" Image32by32="/_imgs/ribbon/newrecord32.png" TemplateAlias="o1" ToolTipTitle="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipTitle" ToolTipDescription="$Resources(EntityDisplayName):Mscrm_SubGrid_EntityLogicalName_MainTab_Management_AddNewStandard_ToolTipDescription" /&gt;
              &lt;/Controls&gt;
          &lt;/Group&gt;
  
  
  
       &lt;CommandDefinitions&gt;
                &lt;CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard"&gt;
                  &lt;EnableRules&gt;
                    &lt;EnableRule Id="new.quote.EnableRule2.EnableRule" /&gt;
                  &lt;/EnableRules&gt;
                  &lt;DisplayRules&gt;
                    &lt;DisplayRule Id="Mscrm.ShowForOneToManyGrids" /&gt;
                    &lt;DisplayRule Id="Mscrm.AppendToPrimary" /&gt;
                    &lt;DisplayRule Id="Mscrm.CreateSelectedEntityPermission" /&gt;
                    &lt;DisplayRule Id="Mscrm.AppendSelected" /&gt;
                    &lt;DisplayRule Id="Mscrm.HideAddNewForChildEntities" /&gt;
                  &lt;/DisplayRules&gt;
                  &lt;Actions&gt;
                    &lt;JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js"&gt;
                      &lt;CrmParameter Value="SelectedEntityTypeCode" /&gt;
                      &lt;CrmParameter Value="PrimaryEntityTypeCode" /&gt;
                      &lt;CrmParameter Value="FirstPrimaryItemId" /&gt;
                      &lt;CrmParameter Value="PrimaryControl" /&gt;
                    &lt;/JavaScriptFunction&gt;
                  &lt;/Actions&gt;
                &lt;/CommandDefinition&gt;
  
  
             &lt;EnableRule Id="new.quote.EnableRule2.EnableRule"&gt;
                  &lt;CustomRule FunctionName="IsUserRoleAdmin" Library="$webresource:Quote_main_library.js" Default="false" InvertResult="true" /&gt;
              &lt;/EnableRule&gt;
  </code></pre>
  
  <p>//Javascript</p>
  
  <pre><code>function IsUserRoleAdmin()
  {
           var currentUserRoles = Xrm.Page.context.getUserRoles();
  
           var isAdmin = false;
            for (var i = 0; i &lt; currentUserRoles.length; i++)
            {
               var userRole = currentUserRoles[i];
              //check admin role 
                      //  if(userRole == "admin guid")
              // {
              //  isAdmin = true;
              // }
             }
  
   return isAdmin;
  }
  </code></pre>