SP007
SP007

Reputation: 1921

CRM2011 subgrid button enable rule

I have 2 issues.

First issue: Trying to hide OOB button in subgrid(Ribbon), based on user role(by calling javascript). Is it possible?

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.

Can anyone please help me?

<Groups Id="Mscrm.SubGrid.quote.MainTab.Groups">
                        <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">
                          <Controls Id="Mscrm.SubGrid.quote.MainTab.Management.Controls">
                            <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" />
                            <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" />
            </Controls>
        </Group>



     <CommandDefinitions>
              <CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard">
                <EnableRules>
                  <EnableRule Id="new.quote.EnableRule2.EnableRule" />
                </EnableRules>
                <DisplayRules>
                  <DisplayRule Id="Mscrm.ShowForOneToManyGrids" />
                  <DisplayRule Id="Mscrm.AppendToPrimary" />
                  <DisplayRule Id="Mscrm.CreateSelectedEntityPermission" />
                  <DisplayRule Id="Mscrm.AppendSelected" />
                  <DisplayRule Id="Mscrm.HideAddNewForChildEntities" />
                </DisplayRules>
                <Actions>
                  <JavaScriptFunction FunctionName="Mscrm.GridRibbonActions.addNewFromSubGridStandard" Library="/_static/_common/scripts/RibbonActions.js">
                    <CrmParameter Value="SelectedEntityTypeCode" />
                    <CrmParameter Value="PrimaryEntityTypeCode" />
                    <CrmParameter Value="FirstPrimaryItemId" />
                    <CrmParameter Value="PrimaryControl" />
                  </JavaScriptFunction>
                </Actions>
              </CommandDefinition>


           <EnableRule Id="new.quote.EnableRule2.EnableRule">
                <CustomRule FunctionName="IsUserRoleAdmin" Library="$webresource:Quote_main_library.js" Default="false" InvertResult="true" />
            </EnableRule>

//Javascript

function IsUserRoleAdmin()
{
         var currentUserRoles = Xrm.Page.context.getUserRoles();

         var isAdmin = false;
          for (var i = 0; i < currentUserRoles.length; i++)
          {
             var userRole = currentUserRoles[i];
            //check admin role 
                    //  if(userRole == "admin guid")
            // {
            //  isAdmin = true;
            // }
           }

 return isAdmin;
}

Upvotes: 0

Views: 2978

Answers (2)

Anwar Noori
Anwar Noori

Reputation: 1

you can use Value Rule to Hide the Button on Ribbon..

to Disable you can use Custom Rule

check this link

Upvotes: 0

Darren Lewis
Darren Lewis

Reputation: 8498

Yes you can hide or disable OOB buttons. This blog post provides some information.

Your js code is incorrect as Xrm.Page.context.getUserRoles() returns an array of GUIDs not the role names so isAdmin will always be false.

Upvotes: 1

Related Questions