在CRM 2011中禁用系统功能区 [英] Disable System Ribbon in CRM 2011

查看:83
本文介绍了在CRM 2011中禁用系统功能区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JavaScript在CRM 2011表单中有条件地禁用System Ribbon = AddNew。这意味着如果statusCode为X或Y,则禁用功能区,该怎么办?

I would like to conditionally disable a System Ribbon = AddNew in a CRM 2011 form with javascript. That means if the statusCode is X or Y disable the Ribbon, how could I do this?

我试图获取功能区的ID来更改的类名,功能区被禁用,但是我得到了空值,因为功能区是异步加载的!

I tryed to get the ID of the Ribbon in order to change the classname of the Ribbon to disabled, but I got Null because the Ribbons are loaded asychronously!

推荐答案

要进一步了解Anwar的答案,使此功能正常工作是拦截并重新利用 AddNew 功能区按钮的功能,但是一旦您这样做,就无需破解功能区DOM。以下是您可以到达那里的一些步骤。

To expand on Anwar's answer, the key to getting this to work is to intercept and repurpose the functionality of the AddNew ribbon button, but once you do, there won't be any need for hacking the Ribbon DOM. Below are a few steps that you can take to get there.

1)创建包含应用程序功能区的解决方案。

2)在SDK中找到Application Ribbon的示例功能区,或使用SDK中包含的解决方案自行构建。

2) Find in the SDK the sample ribbon for the Application Ribbon or build it yourself using the solution included in the SDK.



\sdk\资源\exportedribbonxml

\sdk\resources\exportedribbonxml

\sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml

\sdk\samplecode\cs\client\ribbon\exportribbonxml\exportedribbonxml


3)在应用程序功能区模板中找到您感兴趣的控件,在这种情况下,我假设它是实体子网格中的 AddNew 按钮。在 CustomAction 中重新使用此控件,并使 CustomAction 的位置与您要重新使用的控件同名。

3) Find in the Application Ribbon template the control you're interested in, which I assume in this case is the AddNew button in entity subgrids. Repurpose this control in a CustomAction and make the location of the CustomAction the same name as the control you want to repurpose.

<CustomAction Id="YourOrg.SubGrid.{!EntityLogicalName}.AddNewStandard" 
    Location="Mscrm.SubGrid.{!EntityLogicalName}.AddNewStandard">
  <CommandUIDefinition>
    <Button Id="Mscrm.SubGrid.{!EntityLogicalName}.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" />
  </CommandUIDefinition>
</CustomAction>

4)在应用程序功能区模板中找到此按钮命令的定义,并使用定义作为新的 CommandDefinition 的基础,添加您自己的自定义规则(在这种情况下,新的 EnableRule

4) Find in the Application Ribbon template the definition of the command of this button, and using the exact definition as the basis of a new CommandDefinition, add in your own custom rule (in this case, a new EnableRule).

<CommandDefinition Id="Mscrm.AddNewRecordFromSubGridStandard">
  <EnableRules>
    <EnableRule Id="Mscrm.AppendToPrimary" />
    <EnableRule Id="Mscrm.EntityFormIsEnabled" />
    <EnableRule Id="YourOrg.DisableNewStuff" /> <!--your custom rule-->
  </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>

5)这是Anwar的答案:同时使用 OrRule ValueRule ,定义您的 EnableRule 来检查状态码的实体。链接的演示与一个新的功能区按钮相关,但相同的规则也适用于重新使用的功能区控件。

5) Here is where Anwar's answer comes in: using both the OrRule and the ValueRule, define your EnableRule to check on the statuscodes of the entity. The linked demonstration relates to a new ribbon button, but the same rules work for repurposed ribbon controls as well.

完成后发布更改,功能区应搞定。因为我不确定您对 RibbonXml 的熟悉程度,所以我还会提到 Microsoft拥有一些综合的演练,这些演练对拾起它很有帮助(经过大量的研究!)。

Publish your changes when you're done and your ribbon should be all set. Because I'm not sure how familiar you are with RibbonXml, I'll also mention that Microsoft has some comprehensive walkthroughs that are pretty helpful (after much time studying them!) in picking it up.

这篇关于在CRM 2011中禁用系统功能区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆