Showing posts with label remove Add Existing button. Show all posts
Showing posts with label remove Add Existing button. Show all posts

Friday, July 17, 2009

Hide associated view buttons

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

Suppose we want to hide "Add existing ----" button from associated view.
This assoicated view will be shown in Account entity, and associated view is of some custom entity. then we are requried to add following JavaScript on Account form load event.

====================================

HideAssociatedViewButtons('new_account_new_sponsoredkid', ['Add existing Sponsored Kid 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;
                        }
                    }
                }
            }
        }
    }
}

==================================== 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. Above all contents are referred from http://blog.davehawes.com/post/2008/04/24/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx