javascript crm 2011 如何使用javascript隐藏/显示功能区按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14585141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:01:04  来源:igfitidea点击:

crm 2011 how to hide/show the ribbon button with javascript

javascriptdynamics-crm-2011dynamics-crmdynamics-crm-4

提问by Scorpion

I am trying to hide/show a button from CRM 2011Ribbon on the bases of a condition defined in JavaScript. JavaScript function returns the true/false. So I wan't to change the XML to Hide/Showthe button.

我试图隐藏/显示从一个按钮CRM 2011上定义的条件的基础丝带JavaScript。JavaScript 函数返回true/false. 所以我不想将 XML 更改Hide/Show为按钮。

I have tried to do it as below, but without any luck. Can anyone suggest me correct approach.

我曾尝试按以下方式进行操作,但没有任何运气。谁能建议我正确的方法。

Thanks in Advance

提前致谢

<RibbonDiffXml>
  <CustomActions>
    <CustomAction Id="Email.Form.email.MainTab.Send.CustomAction" Location="Mscrm.Form.email.Send" Sequence="2">
      <CommandUIDefinition>
        <Button Id="Mscrm.Form.email.Send" Command="Mscrm.Form.email.Send_Custom" Sequence="1" Alt="$Resources:Ribbon.Form.email.MainTab.Actions.Send"     LabelText="$Resources:Ribbon.Form.email.MainTab.Actions.Send" Image16by16="/_imgs/SFA/SendAsEmail_16.png" Image32by32="/_imgs/SFA/SendAsEmail_32.png" TemplateAlias="o1" ToolTipTitle="$Resources:Mscrm_Form_email_MainTab_Actions_Send_ToolTipTitle" ToolTipDescription="$Resources:Mscrm_Form_email_MainTab_Actions_Send_ToolTipDescription" />
      </CommandUIDefinition>
    </CustomAction>
  </CustomActions>
  <Templates>
    <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
  </Templates>
  <CommandDefinitions>
    <CommandDefinition Id="Mscrm.Form.email.Send_Custom">
      <EnableRules/>
      <DisplayRules>
        <DisplayRule Id="Mscrm.CanWritePrimary" />
        <DisplayRule Id="Mscrm.Form.email.InDraftOrFailedState" />
        <DisplayRule Id="Mscrm.Form.email.Send.DisplayRule" />
      </DisplayRules>
      <Actions>
        <JavaScriptFunction FunctionName="HideSendEmailButton"     Library="$webresource:sandbox_email.js" />
      </Actions>
    </CommandDefinition>
  </CommandDefinitions>
  <RuleDefinitions>
    <TabDisplayRules />
    <DisplayRules>
      <DisplayRule Id="Mscrm.Form.email.Send.DisplayRule">
        <ValueRule Field="new_type" Value="false" InvertResult="false" />
      </DisplayRule>
    </DisplayRules>
    <EnableRules />
  </RuleDefinitions>
  <LocLabels />
</RibbonDiffXml>

Javascript

Javascript

function HideSendEmailButton() {

     // Query for full name of the current user 
     var userId = Xrm.Page.context.getUserId(); 

    if(userId == '---some Id---')
    {
        return true;
    }
    else
    {
        return false;
    }
}

回答by Greg Oks

You cant really do it (thanks Microsoft)..you can use the enable rules which have the custom rule option where you can use javascript function:

你真的做不到(感谢微软)。你可以使用具有自定义规则选项的启用规则,你可以在其中使用 javascript 函数:

http://msdn.microsoft.com/en-us/library/gg328073.aspx

http://msdn.microsoft.com/en-us/library/gg328073.aspx

But in displsy rule you dont have the customrule option:

但是在 displsy 规则中,您没有 customrule 选项:

http://msdn.microsoft.com/en-us/library/gg334209.aspx

http://msdn.microsoft.com/en-us/library/gg334209.aspx

So there is an example how to use javascript in enable/disable rule:

所以有一个示例如何在启用/禁用规则中使用 javascript:

http://howto-mscrm.com/2011/04/how-to-series-6-how-to-use-customrule.html

http://howto-mscrm.com/2011/04/how-to-series-6-how-to-use-customrule.html