Answered by:
N:N Relationship --Remove 'Add Existing..'

Question
-
Hi there
I have a N:N relationship between contact and a custom entity and I see the 'Add existing..' button on associated views. I know this link:http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx helps to remove the same for 1:N relationship.
Is there a solution to remove the same for N:N relationships.
Wednesday, December 15, 2010 8:54 PM
Answers
-
Use my updated versions of Dave Hawes' code .
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.- Proposed as answer by DavidBerryMVP, Moderator Friday, December 24, 2010 2:13 AM
- Marked as answer by DavidJennawayMVP, Moderator Wednesday, January 26, 2011 5:07 AM
Wednesday, December 15, 2010 9:55 PMModerator
All replies
-
Use my updated versions of Dave Hawes' code .
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.- Proposed as answer by DavidBerryMVP, Moderator Friday, December 24, 2010 2:13 AM
- Marked as answer by DavidJennawayMVP, Moderator Wednesday, January 26, 2011 5:07 AM
Wednesday, December 15, 2010 9:55 PMModerator -
Can you please paste the code here. 'Access Denied' to your page by my company..grrrWednesday, December 15, 2010 11:09 PM
-
function AttachActionToLoadArea(loadAreaId, navigationHandler) { var navElement = document.getElementById('nav_' + loadAreaId); // if at first you don't succeed... if (navElement == null) { navElement = document.getElementById('nav' + loadAreaId); } if (navElement != null) { navElement.attachEvent("onclick", navigationHandler); } } function HideTitledButtons(targetElement, buttonTitles) { var liElements = targetElement.getElementsByTagName('li'); var removedButtons = []; for (var j = 0; j < buttonTitles.length; j++) { for (var i = 0; i < liElements.length; i++) { if (liElements[i].getAttribute('title').substr(0, buttonTitles[j].length) == buttonTitles[j]) { removedButtons.push({ title: liElements[i].getAttribute('title'), element: liElements[i], parent: liElements[i].parentNode, sibling: liElements[i].nextSibling }); liElements[i].parentNode.removeChild(liElements[i]); break; } } } return removedButtons; } function HideViewButtons(Iframe, buttonTitles, outHiddenButtons) { function HideViewButtonsByContext() { if (Iframe.readyState == 'complete') { var iFrame = frames[window.event.srcElement.id]; var hiddenButtonsReturn = HideTitledButtons(iFrame.document, buttonTitles); if (typeof outHiddenButtons != "undefined" && outHiddenButtons != null) { for (hiddenButtonsReturnIndex in hiddenButtonsReturn) { outHiddenButtons.push(hiddenButtonsReturn[hiddenButtonsReturnIndex]); } } } } Iframe.attachEvent("onreadystatechange", HideViewButtonsByContext); } function HideAssociatedViewButtons(loadAreaId, buttonTitles, outHiddenButtons){ function HideViewButtonsByContext() { HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonTitles, typeof outHiddenButtons != "undefined" ? outHiddenButtons : null); } AttachActionToLoadArea(loadAreaId, HideViewButtonsByContext); }
You'll want to use the HideAssociatedViewButtons() method, but it requires the whole code listing. Here are the parameters:loadAreaId : is the string passed to the loadArea() function by the <A> element’s onclick attribute. This is discoverable by using the Developer Toolbar in IE8 by pressing [F12] and using the “Select element by click” feature to view the HTML of the navigation link.
buttonTitles : An array of titles for the buttons to hide. Each array element is a string containing any portion (from the first character) of the “title” attribute of the labeled button/menu item. E.g. the “New XXX” button in an associated view has the title “Add a new XXX to this record”; it’s perfectly acceptable to use the value “Add a new” as one element of this array.
outHiddenButtons (Optional): If you choose to use it, you must pass an array to this parameter. The referenced array will be loaded with elements from the return of the call to HideTitledButtons() .
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.Wednesday, December 15, 2010 11:31 PMModerator -
Hi, Dave
I need this, as well, to work for a N:N relationship where I need to hide 'Add Existing" button in associated view.
I found the page source code on the main entity that contains the associated view info....
id="navnew_valueaddedservices_new_contactrelat, as well as the onclick="loadArea('areanew_valueaddedservices_new_contactrelat' code.
Where do I put the info to get this to work? I can't get it to hide the Add Existing Contact Relationship button.
thank you
AppsTuesday, December 28, 2010 1:50 PM -
Bernardina,
Feed "areanew_valueaddedservices_new_contactrelat" into the HideAssociatedViewButtons first parameter. Something like this:
HideAssociatedViewButtons("areanew_valueaddedservices_new_contactrelat", ["Add existing"]);
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.Tuesday, December 28, 2010 5:05 PMModerator -
Hi, David
Well, I replaced
function HideAssociatedViewButtons("areanew_valueaddedservices_new_contactrelat", ["Add existing"]);
{
function HideViewButtonsByContext() {
HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonTitles,
typeof outHiddenButtons != "undefined" ? outHiddenButtons : null);
}
AttachActionToLoadArea(loadAreaId, HideViewButtonsByContext);
}and it does not work
AppsTuesday, December 28, 2010 5:35 PM -
Heh. You're not supposed to overwrite the code I pasted into this thread. Instead, copy it all, and paste it (along with the line I posted last) into the OnLoad event of the form from which it should run to hide the associated button.
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.Tuesday, December 28, 2010 6:22 PMModerator -
Sorry. I realize that now.
I copied over all of the code onto the onLoad event and added:
HideAssociatedViewButtons("areanew_valueaddedservices_new_contactrelat", ["Add existing"]); as last line
However, it still does not work.
AppsTuesday, December 28, 2010 6:33 PM -
Odd. Do you encounter any scripting errors? Are you certain to have put the code into the "parent" entity form, published it, and then opened/refreshed a record of the parent entity?
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.Tuesday, December 28, 2010 6:44 PMModerator -
I just double-checked everything. No scripting errors. Code is onLoad event of parent form; published; then opened a record from parent entity. Still shows Add Existing button. Your code works for N:N relationships, so that can't be it.
I don't know. frustrating. Let me start from the beginning to review everything.
thanks for your patience and assistance.
I'll post my findings.
AppsTuesday, December 28, 2010 7:09 PM -
I use these scripts myself, so I know they work. Perhaps there's some kind of exception to the deployment you're working in, or the way the relationship is loaded, that isn't accounted for in my code. Only debugging will tell. Best of luck!
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.Tuesday, December 28, 2010 7:24 PMModerator -
I will proceed! Thanks, again!
AppsTuesday, December 28, 2010 7:39 PM