Dynamically Enable/Disable a standard ribbon button based on a form value

There are occations when you need to change the command of an existing ribbon button, without changing the actual button its self. In the Ribbon Xml the Command and the Button are logically separated so that the Command can be used on more than one button.

The Ribbon Workbench for CRM 2011 allows you to easily select a standard button and 'Customise Command'. This creates a copy of the standard command along with enable/display rules for you to modify.

The following video shows the Run Workflow command being enabled/disabled based on a value on the form. Javascript is used to make a call to refreshRibbon when the form value changes. The tutorial assumes you have already installed the Ribbon Workbench as shown by this short video.


The resulting RibbonXml is:

<RibbonDiffXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <CustomActions />
    <RibbonTemplates Id="Mscrm.Templates" />
    <CommandDefinition Id="Mscrm.RunWorkflowPrimary">
        <EnableRule Id="Mscrm.FormStateNotNew" />
        <EnableRule Id="Mscrm.RunWorkflowPrimary" />
        <EnableRule Id="new.contact.FirstnameNotEmpty.EnableRule" />
      <DisplayRules />
        <JavaScriptFunction FunctionName="Mscrm.FormAction.launchOnDemandWorkflowForm" Library="/_static/_forms/form.js">
          <CrmParameter Value="PrimaryEntityTypeCode" />
          <StringParameter Value="" />
    <TabDisplayRules />
    <DisplayRules />
      <EnableRule Id="Mscrm.FormStateNotNew">
        <FormStateRule State="Create" InvertResult="true" />
      <EnableRule Id="Mscrm.RunWorkflowPrimary">
        <CustomRule FunctionName="Mscrm.RibbonActions.enableWorkflowOnForm" Library="/_static/_common/scripts/RibbonActions.js" />
      <EnableRule Id="new.contact.FirstnameNotEmpty.EnableRule">
        <ValueRule Field="firstname" Value="null" InvertResult="true" />
  <LocLabels />


And the refresh ribbon javascript 

function refreshRibbonOnChange()


I hope you agree that using the Ribbon Workbench can shave hours off of your development time when customising the CRM2011 Ribbon!

The Ribbon Workbench for CRM 2011 is a free download.

If you find an issue with the Ribbon Workbench for Dynamics CRM 2011 or have any suggestions, please send it here

Happy Ribbon Customising!


Comments are closed