CRM2011子网格按钮启用规则

时间:2012-11-20 20:06:42

标签: button dynamics-crm-2011 ribbon subgrid

我有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;
}

2 个答案:

答案 0 :(得分:1)

是的,您可以隐藏或禁用OOB按钮。 This blog帖子提供了一些信息。

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

答案 1 :(得分:0)

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

禁用您可以使用自定义规则

check this link