Click here to Skip to main content
11,647,170 members (70,306 online)
Click here to Skip to main content

Enable or Disable Dynamics CRM 2011 Ribbon Control using JavaScript

, 27 Feb 2013 CPOL 14.3K
Rate this:
Please Sign up or sign in to vote.
How to enable or disable the ribbon control using JavaScript.

Introduction

In Dynamics CRM 2011, to Enable or Disable a Ribbon control we have to update the RibbonXml tag of the entity. In this tip, I will show you how to enable or disable the ribbon control using JavaScript.

Background

Every ribbon control has a unique id in Dynamics CRM 2011. E.g., for contact entity, the Save button ID is 'contact|NoRelationship|Form|Mscrm.Form.contact.Save-Large'. If you notice, the button ID is made of 'EnityName|NoRelationship|Form|Mscrm.Form.EntityName.ButtonDisplayNameandSize'. The size of the Save and 'Save & Close' button is large, while 'Save & New' and Delete button are Medium sized. So for the Save& New button, the ID will be 'contact|NoRelationship|Form|Mscrm.Form.contact.SaveAndNew-Medium'.

Using the Code

Following is the JavaScript function for enabling or disabling the button:

//
function HideRibbonControl(formName) {
    
   var saveButtonID = formName + "|NoRelationship|Form|Mscrm.Form." + formName + ".Save-Large";
    var saveandcloseButtonID = formName + "|NoRelationship|Form|Mscrm.Form." + formName + ".SaveAndClose-Large";
    var saveandnewButtonID = formName + "|NoRelationship|Form|Mscrm.Form." + formName + ".SaveandNew-Medium";
    var deactivateButtonID = formName + "|NoRelationship|Form|Mscrm.Form." + formName + ".Deactivate-Medium";
    var deleteButtonID = formName + "|NoRelationship|Form|Mscrm.Form." + formName + ".Delete-Medium";
    HideARibbonButton(saveButtonID);
    HideARibbonButton(saveandcloseButtonID);
    HideARibbonButton(saveandnewButtonID);
    HideARibbonButton(deactivateButtonID);
    HideARibbonButton(deleteButtonID);
}
 
function HideARibbonButton(nameOfButton) {
   var btn = window.top.document.getElementById(nameOfButton);
    var intervalId = window.setInterval(function () {
      if (btn != null) {
        window.clearInterval(intervalId);
        btn.disabled = true;
       }
 
    }, 50);
}
//

Points to Remember

The above JavaScript code works before installing the Roll-up 12. As Roll-up 12 enables support for multi browser capability, the JavaScript code might require some changes.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Thakkar Amit
Program Manager
United States United States
Amit Thakkar is having total work experience over 13 years in implementing projects using various Microsoft Technologies like MS CRM 2011/4.0, Asp.net, C#, MOSS 2007, SSRS and SSIS.

You may also be interested in...

Comments and Discussions

 
Questionit doesn't work Pin
Member 100931364-Jun-13 17:15
memberMember 100931364-Jun-13 17:15 
AnswerRe: it doesn't work Pin
Thakkar Amit19-Jul-13 11:58
memberThakkar Amit19-Jul-13 11:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150804.2 | Last Updated 27 Feb 2013
Article Copyright 2013 by Thakkar Amit
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid