crm 2011如何使用javascript隐藏/显示功能区按钮 [英] crm 2011 how to hide/show the ribbon button with javascript

查看:177
本文介绍了crm 2011如何使用javascript隐藏/显示功能区按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图隐藏/显示来自 CRM 2011 功能区的按钮,基于 JavaScript 。 JavaScript函数返回 true / false 。所以我不想将XML更改为隐藏/显示按钮。

I am trying to hide/show a button from CRM 2011 Ribbon 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/Show the button.

我试过这样做,但没有运气。谁能建议我正确的方法。

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

提前致谢

<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

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


推荐答案

你真的不能这样做(感谢微软)..你可以使用具有自定义规则选项的启用规则,你可以使用javascript函数:

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:

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

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

But in displsy rule you dont have the customrule option:

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

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

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

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

这篇关于crm 2011如何使用javascript隐藏/显示功能区按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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