Custom Rule in Ribbon Customization to enable/disable ribbon button in Dynamics CRM 2011

My requirement is to enable/disable Deactivate ribbon button on Account form based on following condition. In our case CRM gets accounts from other system, if account came from other system to CRM, user should not have capability to deactivate. We have a custom field “ls_cmid” on Account entity, based on this we want enable/disable Deactivate ribbon button. If this field “ls_cmid” value is NULL that means account is created in CRM, if it is not NULL, It came from other system.

Before going thru the steps, hoping you have basic understanding of the RibbonDiffXML.

Step1: Write following JavaScript methods in Account entity script.

//Disable Deactivate ribbon button If account came from CM
function DisableDeactivateButton() {
    var formType = Xrm.Page.ui.getFormType();
    if (formType != 1) {
        var isCMOwned = CheckIfAccountOwnedByCM();
        if (isCMOwned != null && isCMOwned) {
            return false;
        } else {
            return true;
    return true;
//Check if Account came from CM or not
function CheckIfAccountOwnedByCM() {
    if (Xrm.Page.getAttribute('ls_cmid') != null) {
        var cmId = Xrm.Page.getAttribute('ls_cmid').getValue();
        if (cmId != null && cmId.length > 0) {
            return true;
    return false;

Step2: Create a solution for Account entity and export into your local folder. Unzip the solution folder and open Customizations.XML file

Step3: In the CommandDefinition for Deactivate ribbon button you will see the EnableRules. You can have several rules and if any one of the rules returns False, the button will be disabled. Open Customizatons.XML file in Visual Studio and add new EnableRule  under <EnableRules> in <RuleDefinitions> file.

<EnableRule Id="LS.Mscrm.DisableDeactivateButton">
  <CustomRule FunctionName="DisableDeactivateButton" Library="$webresource:ls_script_account" Default="true" />

Step4: Update Deactivate CommandDefination section under <CommandDefinitions> in Customization.XML adding above rule. If you do not have this, you can find the CommandDefination for standard buttons on standard entities in the SDK folder.\sdk\resources\exportedribbonxml\ accountribbon.xml file.

<CommandDefinition Id="Mscrm.Form.Deactivate">
    <EnableRule Id="Mscrm.CanWritePrimary" />
    <EnableRule Id="LS.Mscrm.DisableDeactivateButton" />
    <DisplayRule Id="Mscrm.CanWritePrimary" />
    <DisplayRule Id="Mscrm.PrimaryIsActive" />
    <DisplayRule Id="Mscrm.PrimaryEntityHasStatecode" />
    <DisplayRule Id="Mscrm.PrimaryIsNotActivity" />
    <JavaScriptFunction FunctionName="changeState" Library="/_static/_forms/form.js">
      <StringParameter Value="deactivate" />
      <CrmParameter Value="PrimaryEntityTypeCode" />
      <StringParameter Value="5" />


Filter ribbon button functionality in Dynamics CRM 2011

Found weird issue about Filter ribbon button in CRM 2011, if you browse any entity view, you can click on Filter ribbon button to activate or deactivate the filters on the column headings of view and you can sort out the records by column headings.  This is standard out of the box (OOTB) functionality; it works for all system and custom entity views.

After we search something using Quick Find view, Filter ribbon gets disabled, not sure why it is getting disabled. For now I could not find any solution. Let me know if you have any solution to enable Filter ribbon button in Quick Find views.



Create a custom ribbon button on entity Homepage ribbon and get the selected record in Dynamics CRM 2011

Download CRM 2011 Visual Ribbon Editor tool from the following codeplex URL.

1. Establish CRM connection


2. Select the entity to customize and click ‘OK’ to load entity ribbon customizations


3. Select ‘Homepage’ from Ribbon type dropdown list.


4. Select any ribbon button and click on ‘New Button’

5. Update the Ribbon button options in ‘Details’ tab.


6. Update the JavaScript options in ‘Action’ tab.


a. Add JavaScript function
Function Name: JavaScript function calling in ribbon button click
Library: JavaScript web resource name

b. Add CRM parameter and select the value as ‘SelectedControlSelectedItemReferences’

JavaScript code to get the selected record

function GetContacts(selectedEntityRefs)
alert("Id: " + selectedEntityRefs[0].Id +
"\n Name: " + selectedEntityRefs[0].Name +
"\n TypeCode: " + selectedEntityRefs[0].TypeCode +
"\n TypeName: " + selectedEntityRefs[0].TypeName);