locked
How to Hide 'Add existing button' for many to many relationship RRS feed

  • Question

  • Hi ,

    I have created a custom entity with a M-M realtionship with the account entity.  I want to hide the 'Add existing' option from the associated view. The code that I found on the internet works fine for 1-M relationships but does not work for M:M. Is there anything different that I need to do to hide the option on the associated view of a M:M relationship.

    Thanks in advance

    Code:

    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 = 'hidden';
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
     
    HideAssociatedViewButtons('areanew_new_involvement_contact', ['Add existing Involvement to this record']); //To hide the button

     

    Thursday, November 19, 2009 9:49 AM

Answers

  • To be honest, I don't know what the problem is, then.  At this point, I'd say that you may be better off using IE8's built-in debugger and step through the code to see where its failing.  The code could fail if, for some reason or another, the IFrame was loading before the code was being executed... since the code is attached to the IFrame's onreadystatechange handler.  However, this should be improbable if the code were executing in the form's OnLoad script.

    I noticed above that you said you were using the IE Dev Toolbar to locate the id attribute of the IFrame, but then state that you read the id needed to be prefixed with the 'area' keyword.  This is incorrect.  You always use the id attribute of the Iframe holding the view.  The IE Dev Toolbar should confirm that the id is prefixed with 'area'.  If, for some reason, it is not, then do not use the prefix.
    Dave Berry
    Tuesday, December 1, 2009 1:37 AM
    Moderator

All replies

  • Hi,

    You could check for ids of the following loadAreaId and IframeId.

    document.getElementById('nav_' + loadAreaId);
    document.getElementById(loadAreaId + 'Frame')


    Regards,
    Nishant Rana

    http://nishantrana.wordpress.com
    Thursday, November 19, 2009 10:15 AM
  • Can you please elaborate a bit as I did not understand what you meant.
    Thursday, November 19, 2009 10:17 AM
  • Hi,

    I mean, you could check for the id of the load Area as well as Iframe.
    Are they starting from 'nav_' and have 'Frame' in end respectively,
    You could use IE Developer tool for that.

    Regards,
    Nishant Rana

    http://nishantrana.wordpress.com
    Thursday, November 19, 2009 10:48 AM
  • Hi Nishant,

    I am using the IE developer tool and getting id's from there. I read some where on the internet that for the laod area id of a M:M relationship  we need prefix it with area. Tried that even still does not work. The code works fine with a 1:M relationship as I have tried that but does not work for a M:M.
    Thursday, November 19, 2009 10:53 AM
  • The IE developer tool may be providing the proper 'id' to use.  I have seen some diversion among this code between using 'hidden' and 'none' as the display style to set.  Personally, I've always used 'none', but I think 'hidden' alleviates some issue with the buttons reappearing if the window is resized, or something like that.  However, I've noticed that 'hidden' doesn't always work.  Try using this minor variation in the code:

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

    Dave Berry
    Friday, November 20, 2009 1:34 AM
    Moderator
  • Hi,

    It still does not work

    Friday, November 20, 2009 12:17 PM
  • Ok, how about this:

    You state "I have created a custom entity with a M-M realtionship with the account entity."  and your IFrame reference is this:  'areanew_new_involvement_contact'

    That looks like a 1-to-Many relationship between the Involvement and Contact, which does not need an 'area' before it.


    Dave Berry
    Friday, November 20, 2009 6:43 PM
    Moderator
  • Hi David,

    Its a many to many relationship. I have put the area before the new_new_involvement contact because I read some where on the web that we need the prefix the areaid with area. i have tried it without area as well. It still does not work.
    Monday, November 23, 2009 2:56 PM
  • Yes, but I'm saying the name of the relationship doesn't indicate that it's between the Involvement and Account records, but between the Involvement and Contact records.  You've identified the M-to-M relationship between the Involvement and Account, but you haven't said anything about how the Involvement and Contact are related.  Assuming they're also M-to-M, then the relationship name you're using should work to remove the "Add Existing" button on the Involvement grid from the Contact entity's form... not the Account form.

    Dave Berry
    Monday, November 23, 2009 8:22 PM
    Moderator
  • The M:M relationship is between the contact and the involvement entity.

    Tuesday, November 24, 2009 9:14 AM
  • To be honest, I don't know what the problem is, then.  At this point, I'd say that you may be better off using IE8's built-in debugger and step through the code to see where its failing.  The code could fail if, for some reason or another, the IFrame was loading before the code was being executed... since the code is attached to the IFrame's onreadystatechange handler.  However, this should be improbable if the code were executing in the form's OnLoad script.

    I noticed above that you said you were using the IE Dev Toolbar to locate the id attribute of the IFrame, but then state that you read the id needed to be prefixed with the 'area' keyword.  This is incorrect.  You always use the id attribute of the Iframe holding the view.  The IE Dev Toolbar should confirm that the id is prefixed with 'area'.  If, for some reason, it is not, then do not use the prefix.
    Dave Berry
    Tuesday, December 1, 2009 1:37 AM
    Moderator