Geet B
Geet B

Reputation: 21

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

Upvotes: 2

Views: 8383

Answers (5)

glosrob
glosrob

Reputation: 6715

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);
}

Upvotes: 3

Michael Philip
Michael Philip

Reputation: 81

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

Upvotes: 0

Renaud Dumont
Renaud Dumont

Reputation: 1806

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.

Upvotes: 3

Steve
Steve

Reputation: 103

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");

Upvotes: 1

Luke Baulch
Luke Baulch

Reputation: 3656

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/

Upvotes: 2

Related Questions