"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Tuesday, 3 January 2012

How to override System Ribbon Button in CRM 2011 ( Display / Enable Rule to System Ribbon Button in CRM 2011)

This post would shed light on the following.
How to override System Ribbon Button in CRM 2011 ( Display / Enable Rule to System Ribbon Button in CRM 2011)?
How to show / hide a system button based on a value on the form?


In CRM 2011, it is possible to override the System ribbon button functionality. Also we could apply Enable / Disable Rule Display / Hide Rule to the existing System Ribbon button.
In order to grasp this quickly, lets consider a scenario.


As we all know, there is a Deactivate system ribbon button on the Account form.
Suppose we would like to Enable / Disable this button based on a value on the Account form. To make it simple, lets consider the City field. 
For instance, if the city is London, then Deactivate system button should be enabled. Also we should be able to fire our custom javascript when the Deactivate System button gets clicked. This sample could take you through very useful scenarios.


There is a key to unlock the door here. what is that key ? Lets see.


If you refer the SDK, you could find the following folder and file


sdk\resources\exportedribbonxml\accountribbon.xml


Lets find out our System Deactivate button.


Please Note: We don't need to write the following piece of code. This is just an easy way to refer and then to find the key from SDK.
<Button Id="Mscrm.Form.account.Deactivate" ToolTipTitle="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" ToolTipDescription="$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Deactivate" Command="Mscrm.Form.Deactivate" Sequence="60" Alt="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" LabelText="$Resources:Ribbon.HomepageGrid.account.Record.Status.Deactivate" Image16by16="/_imgs/ribbon/deactivate16.png" Image32by32="/_imgs/ribbon/Deactivate_32.png" TemplateAlias="o2" />


Now can you guess what's the key in this? Its nothing but the Command.


The only key thing we need to override the System Ribbon button is to know the command value. Rest is as easy as we open a door with a valid key. We need to write the CommandDefinition as shown below.




Please make sure that the code is written under right parent tags.



          <CommandDefinition Id="Mscrm.Form.Deactivate">
            <EnableRules>
              <EnableRule Id="Mscrm.Form.account.Deactivate.EnableRule"></EnableRule>
            </EnableRules>
            <DisplayRules></DisplayRules>
            <Actions>
              <JavaScriptFunction Library="$webresource:ap_DeactivateOverride.js" FunctionName="DeactivateOverride" />
            </Actions>
          </CommandDefinition>




Also the enable rule under rule definitions as show in the above picture.

         <EnableRule Id="Mscrm.Form.account.Deactivate.EnableRule">
              <ValueRule Field="address1_city" InvertResult="false" Value="London"/>
            </EnableRule>


Here we go.


Scenario1: City value is not London -- Deactivate Button got disabled.






Scenario2: City value is London -- Deactivate Button got enabled.



Scenario3: City value is London -- Deactivate Button was clicked by the user. (alert from custom js function)




As this is my first post in 2012,

"тнєяє ѕнαℓℓ вє ѕнσωєяѕ σƒ вℓєѕѕιηg тσ уσυ αℓℓ ιη тнє вℓσωιηg ƒℓσωєя -2012"














2 comments:

  1. Hi there,

    would you be able to provide me the javascript code snippet please?

    I would love to see how the javascript code hooks in within the ribbon context.

    ReplyDelete
  2. Hi, Am running CRM 2013 on Premise. I hope you can help me.

    In the lead form I would like to disable the Qualify button on form load and only enable the button when a particular field has been populated.
    I don't want to make the field required by default as it will stop users saving the record. I want them to be able to create and save a lead but disable qualify until they fill particular fields.

    I would like to do the same in the opportunity by disabling the Close as won button some fields have been populated.

    ReplyDelete