Hide 'Add Existing…' Button

I just got the requirement to hide ‘Add existing button’ from the associated view’s toolbar.  Thanks to Dave for his post at http://blog.davehawes.com/page/Remove-Add-Existing-xxxxx-to-this-record-button-version-1.aspx

i did some modification and it worked for me.

Just remember to call ‘HideAssociatedViewButtons’ with proper arguments, it takes two argument first ID of the link in left navigation area and second is the title of that button both can be picked with IE toolbar easily and put this code Onload of the entity form in which you want to hide that button.

 

HideAssociatedViewButtons(‘id of the link from left navigation’, ‘Add existing  …….. to this record’);

function HideAssociatedViewButtons(loadAreaId, buttonTitles)
{         var isNativeEntity = false;
        var navElement = document.getElementById(‘nav_’ + loadAreaId);
        if (navElement == null)
        {
                navElement = document.getElementById(‘nav’ + loadAreaId);
                isNativeEntity = true;
        }

        if (navElement != null)
        {
            navElement.onclick = function LoadAreaOverride()
            {
                // Call the original CRM method to launch the navigation link and create area iFrame
            if (isNativeEntity)
                {
                    loadArea(‘area’ + loadAreaId);
                    HideViewButtons(document.getElementById(‘area’ + loadAreaId + ‘Frame’), buttonTitles);
                 }
            else
                {
                    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 i = 0; i < liElements.length; i++)
                    {                         if (liElements[i].getAttribute(‘title’) == buttonTitles)
                        {
                            liElements[i].style.display = ‘none’;
                            break;
                        }
                 }
             }
        }
    }
}

 

Hope it will help somebody.

One thought on “Hide 'Add Existing…' Button

Leave a Reply

Your email address will not be published. Required fields are marked *