0

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;
}
SP007
  • 1,871
  • 1
  • 22
  • 31

2 Answers2

1

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.

Darren Lewis
  • 8,338
  • 3
  • 35
  • 55
  • Thanks for reply. But as I said, subgrid button enable rule is unable to call javacript function. – SP007 Nov 21 '12 at 15:02
0

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

to Disable you can use Custom Rule

check this link

  • Welcome to Stack Overflow! We appreciate the link, but it would be better if you could make it so that people only need to look at your answer to solve this problem. It's good to have the link for reference, but that shouldn't be most of you answer. – Sam Mussmann Dec 07 '12 at 17:24