locked
Disable new opp product on opportunity RRS feed

  • Question

  • Hi

    I want to disable the new opportunity product button. I am using the following url code but it's not hiding the button and no error onload of opportunity.

    http://blog.davehawes.com/post/2008/04/23/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx

    I am passing the parameters like below.

    HideAssociatedViewButtons('product_opportunities', ['Add a new Opportunity Product 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;
                            }
                        }
                    }
                }
            }
        }
    }

    I don't know where i am doing wrong.

    Regards,

    NAG.

    Sunday, January 8, 2012 7:52 PM

Answers

  • Yeah it appears that your 'loadAreaId' is off a bit and also the blog code didn't work for me in this scenario.  This worked for me:

    function HideAssociatedViewButtons(loadAreaId, leftNavId, buttonTitles){
        var navElement = document.getElementById(leftNavId);
       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('areaProducts', 'navProducts', ['Add a new Opportunity Product to this record']); 
    



    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
    • Proposed as answer by Blake ScarlavaiMVP Monday, January 9, 2012 1:52 PM
    • Marked as answer by crmpnk1 Monday, January 9, 2012 3:28 PM
    Sunday, January 8, 2012 11:07 PM

All replies

  • put debugger; in your first method and step through it to make sure you are passing the correct IDs to find the elements.
    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
    Sunday, January 8, 2012 10:55 PM
  • Yeah it appears that your 'loadAreaId' is off a bit and also the blog code didn't work for me in this scenario.  This worked for me:

    function HideAssociatedViewButtons(loadAreaId, leftNavId, buttonTitles){
        var navElement = document.getElementById(leftNavId);
       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('areaProducts', 'navProducts', ['Add a new Opportunity Product to this record']); 
    



    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
    • Proposed as answer by Blake ScarlavaiMVP Monday, January 9, 2012 1:52 PM
    • Marked as answer by crmpnk1 Monday, January 9, 2012 3:28 PM
    Sunday, January 8, 2012 11:07 PM
  • Thank you. it worked for me.  May i know how to find out the parameters, if i want to do the same for another entity ?

    'areaProducts', 'navProducts', ['Add a new Opportunity Product to this record']);


    Monday, January 9, 2012 5:36 AM
  • Go to an Opportunity record and press F12 in IE and it will open the Dev Toolbar.  Then click the mouse pointer at the top left of the Dev Toolbar.  Now hover over the Products left nav link and it should be highlighted by the Dev Toolbar.  Click it and it will take you to the element for that left nav link and you can scroll to the right to find it's ID.

    That will give you the left nav id "navProducts".  For the area ID you need to click the Products left nav so that it loads the Opp Product grid on the right.  Then click the mouse pointer in Dev Toolbar again and then hover over the left side of the "New Opportunity Product" button so that the right frame will highlight with a border and then click it.  This should put you close to the iframe in Dev Toolbar so you can find the ID.

     


    Blake Scarlavai - http://mscrmdev.blogspot.com/ - Sonoma Partners - http://www.sonomapartners.com/ - Follow @bscarlav
    Monday, January 9, 2012 2:03 PM
  • Thanks Blake. I thought all the names are mentioned in SDK.
    • Edited by crmpnk1 Monday, January 9, 2012 3:28 PM
    Monday, January 9, 2012 3:27 PM