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

7 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Hi There,
    i have tried the above listed two functions into the onload event of one entity. but i don't know why it did not work at all.
    during the testing what i had found is it did not even go into the code right after the following line
    var navElement = document.getElementById('nav_' + loadAreaId);

    then i had added the following few lines to check wheather it works or not
    if (navElement == null)
    {
    navElement = document.getElementById('nav' + loadAreaId);
    isNativeEntity = true;
    }

    if (navElement != null)
    {
    }

    could any one help me out to resolve this issue.
    it would highly appreciated
    thanks in advance

    ReplyDelete
  3. Thanks,
    It helps me

    ReplyDelete
  4. this work only for parental relationship???

    ReplyDelete
  5. could anyone provide the above code but where it is hiding the export to excel button?

    many many thanks

    ReplyDelete
  6. Everything we see hides another thing, we always want to see what is hidden by what we see. See the link below for more info.


    #hides
    www.ufgop.org

    ReplyDelete