Monday, July 12, 2010

MSCRM 4 - Remove 'Add Existing xxxxx to this record' button

In our CRM implementation where we created several custom entities. It displayed an 'Add Existing xxxxx to this record' button when it was not required and created a lot of confusion among the users. I tried to remove them and like always instead of reinventing the wheel I binged it and then this come to my rescue and within minutes the needful was done. Thanks Dave and 'Dynamic Methods' for this beautiful post. the code that was posted there is :

HideAssociatedViewButtons('new_business_new_surveys', ['Add existing Survey to this record', 'Add a new Survey to this record']);
HideAssociatedViewButtons('new_account_new_eventinvite', ['Add existing Event Invite to this record']);

function HideAssociatedViewButtons(loadAreaId, buttonTitles){
var navElement = document.getElementById('nav_' + loadAreaId);
if (navElement != null) {
navElement.onclick = function LoadAreaOverride() {
// Call the original CRM method to launch the navigation link and create area iFrame
loadArea(loadAreaId);
HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonTitles);
}
}
}

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') == buttonTitles[j]) {
liElements[i].style.display = 'none';
break;
}
}
}
}
}
}
}

No comments: