0

我有2个问题。

第一个问题:试图隐藏子网格(功能区)中的OOB按钮,基于用户角色(通过调用javascript)。是否可以?

第二个问题:通过“enablerule”javascript隐藏OOB按钮是不可能的,所以我尝试使用“enablerule”/javascript来禁用按钮。这是上面反映的以下代码。仍然不工作,但对于主窗体功能区按钮,下面的代码工作。

谁能帮帮我吗?

<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;
}
4

2 回答 2

1

是的,您可以隐藏或禁用 OOB 按钮。 这篇博文提供了一些信息。

您的 js 代码不正确,因为Xrm.Page.context.getUserRoles()返回的是 GUID 数组而不是角色名称,因此 isAdmin 将始终为 false。

于 2012-11-20T21:55:10.153 回答
0

您可以使用值规则隐藏功能区上的按钮..

to Disable you can use Custom Rule

check this link

于 2012-12-07T16:55:53.907 回答