简体   繁体   中英

Getting Id of Ribbon Button In CRM 2011

I created one javascript in which i want to hide ribbon Reactivate Lead button depending on some condition.

I got the Id of the button by pressing F12 on form which is lead|NoRelationship|Form|Mscrm.Form.lead.ReactivateLead-Large .

In jscript , to get that button -

document.getElementById("lead|NoRelationship|Form|Mscrm.Form.lead.ReactivateLead-Large");

but I am not getting that button, its giving me null .. I am not getting what is the problem . please let me know if anybody has suggetions.

thanks

The reason why you retrieve a null value is because the ribbon menu is displayed asynchronously. So if you try to retrieve the button when the onload event of the form is triggered, the button won't necessarily be in the DOM already.

The link provided by Luke will show you the right way to do this.

You can hide buttons in CRM2011 by altering the Entity customization XML.

Have a look at this: http://gtcrm.wordpress.com/2011/02/23/hiding-a-ribbon-button-in-crm-2011/

This should work, but you might need to hold your nose whilst using it

function HideARibbonButton(nameOfButton) {
    var intervalId = window.setInterval(function () {
        if (window.top.document.getElementById(nameOfButton) != null) {
            window.clearInterval(intervalId);

            //top menu has loaded
            window.top.document.getElementById(nameOfButton).style.visibility = 'hidden';
        }
    }, 100);
}

I also found that if you don't use window.top before document.. it doesn't always work.

My code always starts with window.top.document etc..

see below:

tabSave = window.top.document.getElementById("salesorder|NoRelationship|Form|Mscrm.Form.salesorder.MainTab.Save");

You are getting null because the ribbon takes some time to display so you have to set an interval (code to be executed every 2 second for example) in which you place your code which will hide the button.

Or, you can display rule which control the visibility of the button depending on the Boolean value returned by a java script function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM