Wednesday, September 9, 2009

Script for hide 'Add existing button' in MS CRM 4.0

Sometimes it required to hide the “add existing” button from the grid. Here is the Jscript to achieve the same. There is a Test entity (custom entity) in Contact entity where I am hiding the “add existing” button.

//Script for hide 'Add existing button'

HideAddExistingButton('new_contact_test', ['Add existing Test to this record']);

function HideAddExistingButton(relationshipName, buttonToolTip)
{
var navElement = document.getElementById('nav_' + relationshipName);
if (navElement != null)
{
navElement.onclick = function LoadAreaOverride()
{
loadArea(relationshipName);
HideButton(document.getElementById(relationshipName + 'Frame'), buttonToolTip);
}
}
}



function HideButton(Iframe, buttonToolTip)
{
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 < buttonToolTip.length; j++)
{
for (var i = 0; i < liElements.length; i++)
{
if (liElements[i].getAttribute('title') == buttonToolTip[j])
{
liElements[i].style.display = 'none';
break;
}
}
}
}
}
}


“relationshipName” you can get it from the entity customization, it’s basically the relationship name in between the entities. “buttonToolTip” is the tool tip defined for the add exixting button.

No comments: