To show only account or contact in customer lookup, follow the below steps
1) On Load of form add the following code
if (Xrm.Page.getControl("customerid") != null) {
Xrm.Page.getControl("customerid").addPreSearch(function () {
filterCustomerLookup ();
});
}
2)Register this function on OnChange event of customer lookup to show only account in customer lookup
function filterCustomerLookup () {
var lookup = Xrm.Page.getControl('customerid');
//check if multiple type dropdowns enabled for this lookup
if (lookup.getEntityTypes().length > 1) {
lookup.setEntityTypes(['account']);
}
var fetchXml = "<filter type='and'>";
fetchXml += "<condition attribute='statecode' operator='eq' value='0'/>";
fetchXml += "</filter>";
if (Xrm.Page.getAttribute("customerid") != null) {
Xrm.Page.getControl("customerid").addCustomFilter(fetchXml, "account");
}
}
To show only contact then change account to contact.
function filterCustomerLookup () {
var lookup = Xrm.Page.getControl('customerid');
//check if multiple type dropdowns enabled for this lookup
if (lookup.getEntityTypes().length > 1) {
lookup.setEntityTypes(['account']);
}
var fetchXml = "<filter type='and'>";
fetchXml += "<condition attribute='statecode' operator='eq' value='0'/>";
fetchXml += "</filter>";
if (Xrm.Page.getAttribute("customerid") != null) {
Xrm.Page.getControl("customerid").addCustomFilter(fetchXml, "contact");
}
}