Hide New Button on Lookups and Subgrids – CRM 2013 & 2015

Sometimes, you don’t want the New button to be available for creating new records from a lookup or subgrid’s lookup:

lookup_before
lookup_after

In order to hide the standard New button on a lookup, use the following function (works on both CRM 2013 and CRM 2015):

function RemoveNewButtonFromLookUp(lookupName)
{	
	if(lookupName)
	{
		var lookUpControl = Xrm.Page.getControl(lookupName);
		
		if(lookUpControl)
		{
			lookUpControl.addPreSearch(function () {
				setTimeout(function() {
					document.getElementById("Dialog_" + lookupName + "_i_IMenu").childNodes[1].childNodes[1].style.display = "none";
				}, 100);
			});
		}
	}
}

To hide the New button on a subgrid form, use the following function:

function RemoveNewButtonFromSubGridLookUp(subgridName)
{
	if(subgridName)
	{
		document.getElementById(subgridName + "_addImageButtonImage").addEventListener("click", function () {
                setTimeout(function () {
                    var gridControl = Xrm.Page.getControl(subgridName);
                    var lookUpControl = gridControl.$c_0.$N_4.$Y_3; // CRM 2015
		    //var lookUpControl = gridControl.$c_0.$I_4.$3M_3.$3_6; // CRM 2013
					
		    if(lookUpControl)
		    {
			lookUpControl.addPreSearch(function () {
				setTimeout(function() {
					document.getElementById("Dialog_lookup_" + subgridName + "_i_IMenu").childNodes[1].childNodes[1].style.display = "none";
				}, 100);
			});
		    }
                }, 1000);
            });
	}
}

Usage:

RemoveNewButtonFromLookUp("mylookupid");
RemoveNewButtonFromSubGridLookUp("mysubgridname");

Leave a comment

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