Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

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

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.

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

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;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

But in displsy rule you dont have the customrule option:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...