Remove Existing Buttons from CRM Pages

This is something that when we upgraded one of our systems from 3 to 4 identified. This was a something we wanted to hide and i wanted to get some ideas from the web regarding this.
Fortunetly for me there was very good article by Dave Hawes. http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx

I used this article to get an idea. After reading this article i was able to get a clear idea of how to do this, but i wanted a generic solution as i wanted to apply this to all the CRM forms. i have pasted below the javascript i used.



var navGroup= document.getElementById('crmNavBar');
if (navGroup != null)
{
var x= navGroup.getElementsByTagName('li');
if (x != null)
{
//First 3 links are for the same entity, activity and activty history, Hence i removed them.
for( var i = 2; i < x.length ; i++ )
{
//getting the dive area. Refer below
var Div = x[i].innerHTML;
//get the index of id
var T = Div.indexOf('id');
//get the index of class
var T2 = Div.indexOf('class');
//get the value of title
var Title = (Div.substring(T+3,T2));

if (Title.indexOf('nav_') !=-1)
{
Title = Title.substr(4,Title.length-5);
}
else if (Title.indexOf('nav') !=-1)
{
Title = Title.substr(3,Title.length-4);
}

//Sub Accounts are different when treated by this javascript
if (Title.toLowerCase() != 'subact')
{
HideAssociatedViewButtons2(Title);
}
else
{

HideAssociatedViewButtons('SubAccts', ['Add existing Member to this record']);

}

}
}
}


function HideAssociatedViewButtons2(loadAreaId)
{

var isNativeEntity = false;
var navElement = document.getElementById('nav_' + loadAreaId);

if (navElement == null) {
navElement = document.getElementById('nav' + loadAreaId);
isNativeEntity = true;
}



if (navElement != null) {
navElement.onclick = function LoadAreaOverride()
{
if (isNativeEntity)
{
loadArea('area' + loadAreaId);
HideViewButtons2(document.getElementById('area' + loadAreaId + 'Frame'));
}
else
{
loadArea(loadAreaId);
HideViewButtons2(document.getElementById(loadAreaId + 'Frame'));
}
}
}
}



function HideViewButtons2(Iframe)
{


if (Iframe != null ) {
Iframe.onreadystatechange = function HideTitledButtons() {
if (Iframe.readyState == 'complete') {
var iFrame = frames[window.event.srcElement.id];
var liElements = iFrame.document.getElementsByTagName('li');
for (var i = 0; i < liElements.length; i++) {
if (liElements[i].getAttribute('title').indexOf('Add existing') !=-1){
liElements[i].style.display = 'none';
break;
}
}
}
}
}
}


function HideAssociatedViewButtons(loadAreaId, buttonTitles)
{

var navElement = document.getElementById('navSubAct');
navElement.onclick = function LoadAreaOverride()
{
loadArea('area' + loadAreaId);
HideViewButtons(document.getElementById('area' + loadAreaId + 'Frame'), ['Add existing Member to this record']);
}

}



function HideViewButtons(Iframe, buttonTitles)
{
if (Iframe != null ) {
Iframe.onreadystatechange = function HideTitledButtons() {
if (Iframe.readyState == 'complete') {
var iFrame = frames[window.event.srcElement.id];
var liElements = iFrame.document.getElementsByTagName('li');
for (var j = 0; j < buttonTitles.length; j++) {
for (var i = 0; i < liElements.length; i++) {
if (liElements[i].getAttribute('title').indexOf('Add existing') !=-1)
{
liElements[i].style.display = 'none';
liElements[i].style.visibility = 'hidden';
break;
}
}
}
}
}
}
}

DIV is similar to the below statement.

Associate Members


I would like to thank Dave and all the contributors for the their comments in the above mentioned post as without that i wouldn't be able to come up with this. Thanks mates.

Cheers.

Comments

Popular posts from this blog

Error message “User does not have send-as privilege.” when sending emails programmatically in CRM 2011