Argos
Phil's CRM Blog | Dave Hawes Blog | MSCRM 4 - Remove 'Add Existing xxxxx to this record' button

Dave Hawes Blog | MSCRM 4 - Remove 'Add Existing xxxxx to this record' button

by Phil Adams 4. March 2010 14:37

 

I've been working on a MS CRM 4 project and found that the custom entities that we added displayed an 'Add Existing xxxxx to this record' button when it was not required and created a lot of confusion among the users.

Microsoft have said they will make this optional 'In the next release' but that is not soon enough for me!

After working through various ideas on how to solve this with Ian Crowther and Steve Vallance we came up with the following fix. Thanks also to 'Dynamic Methods' for this post about hiding buttons: http://dmcrm.blogspot.com/2008/01/hiding-buttons-in-mscrm-40.html

This javascript should be added to the onLoad event for the form of the entity where you want to hide buttons for the associated views of other entities. You then need to call the function HideAssociatedViewButton for each associated entity - passing in the name of the dataArea div tag and the title of the button you need to remove. (this can be found by using the IE Developer toolbar):

The original code snippet (version 1) can be found here:

http://blog.davehawes.com/page/Remove-Add-Existing-xxxxx-to-this-record-button-version-1.aspx

This version (version 2) has been updated thanks to the contribution from David Berry. His code splits out the hiding of buttons when an iFrame is loaded into a separate function. It also allows multiple buttons to be hidden which is very useful as well as allowing the function to be used to hide buttons in other iFrames as well. Many thanks David.

hide-associated-view-buttons-v2.js.txt (1.41 kb)

HideAssociatedViewButtons('new_business_new_surveys', ['Add existing Survey to this record', 'Add a new Survey to this record']);
HideAssociatedViewButtons('new_account_new_eventinvite', ['Add existing Event Invite 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; 
                        }
                    } 
                } 
            } 
        } 
    }
} 

Dave Hawes Blog | MSCRM 4 - Remove 'Add Existing xxxxx to this record' button

Tags:

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



About Phil

Phil has been working with CRM since the BETA of CRM v1.0 and has seen a lot of the problems arising from installation, maintenance and Development.

Phil specializes in the ISV area of CRM; Creating Add-Ons and Plugins for various clients.

Phil currently works as a Microsoft Dynamics CRM Consultant and Developer for Cambridge Online Systems Ltd In the UK.

Phil also has several Microsoft Certifications in .NET and CRM