Tuesday, July 6, 2010

Hide associated view buttons(Buttons those are showing in related entity)

Some time user not required some buttons to be shown in associated (related entity view) grid menu.To hide associated(related entity view) buttons we are required to Add JavaScript on the form OnLoad event of entity, in which this assicated view is shown.

For example:- I have add entity with name Audit in CRM and associate it with Account, Now I tried to hide Audit assiciated button's Add New and Add Existing Item from Audit entity, but I saw ID's of these buttons not exist in Account entity source becuase associated entity open in Iframe, so for this we requried to add following JavaScript on Account form load event.

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

HideAssociatedViewButtons function requires loadAreaId, buttonTitles as a parameters.
We can find this loadAreaID, by viewing source code of Account form. and buttonTitles means ToolTip of that button.

for Example:- HideAssociatedViewButtons('new_lead_custom_audit', ['Add existing Audit to this record', 'Add a new Audit to this record']);

Content refereed from http://mahadeomatre.blogspot.com/2009/07/hide-associated-view-buttons.html

No comments:

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...