title: crm 2011 how to hide/show the ribbon button with javascript
body: <p>I am trying to hide/show a button from <code>CRM 2011</code> Ribbon on the bases of a condition defined in <code>JavaScript</code>. JavaScript function returns the <code>true/false</code>. So I wan't to change the XML to <code>Hide/Show</code> the button. </p>
  
  <p>I have tried to do it as below, but without any luck. Can anyone suggest me correct approach. </p>
  
  <p>Thanks in Advance</p>
  
  <pre><code>&lt;RibbonDiffXml&gt;
    &lt;CustomActions&gt;
      &lt;CustomAction Id="Email.Form.email.MainTab.Send.CustomAction" Location="Mscrm.Form.email.Send" Sequence="2"&gt;
        &lt;CommandUIDefinition&gt;
          &lt;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" /&gt;
        &lt;/CommandUIDefinition&gt;
      &lt;/CustomAction&gt;
    &lt;/CustomActions&gt;
    &lt;Templates&gt;
      &lt;RibbonTemplates Id="Mscrm.Templates"&gt;&lt;/RibbonTemplates&gt;
    &lt;/Templates&gt;
    &lt;CommandDefinitions&gt;
      &lt;CommandDefinition Id="Mscrm.Form.email.Send_Custom"&gt;
        &lt;EnableRules/&gt;
        &lt;DisplayRules&gt;
          &lt;DisplayRule Id="Mscrm.CanWritePrimary" /&gt;
          &lt;DisplayRule Id="Mscrm.Form.email.InDraftOrFailedState" /&gt;
          &lt;DisplayRule Id="Mscrm.Form.email.Send.DisplayRule" /&gt;
        &lt;/DisplayRules&gt;
        &lt;Actions&gt;
          &lt;JavaScriptFunction FunctionName="HideSendEmailButton"     Library="$webresource:sandbox_email.js" /&gt;
        &lt;/Actions&gt;
      &lt;/CommandDefinition&gt;
    &lt;/CommandDefinitions&gt;
    &lt;RuleDefinitions&gt;
      &lt;TabDisplayRules /&gt;
      &lt;DisplayRules&gt;
        &lt;DisplayRule Id="Mscrm.Form.email.Send.DisplayRule"&gt;
          &lt;ValueRule Field="new_type" Value="false" InvertResult="false" /&gt;
        &lt;/DisplayRule&gt;
      &lt;/DisplayRules&gt;
      &lt;EnableRules /&gt;
    &lt;/RuleDefinitions&gt;
    &lt;LocLabels /&gt;
  &lt;/RibbonDiffXml&gt;
  </code></pre>
  
  <p><strong>Javascript</strong></p>
  
  <pre><code>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;
      }
  }
  </code></pre>