Wednesday, January 10, 2018

How to restrict Customer field for specific record type?

Customer field allow the users to select Account/Contact. So, to restrict Customer field in such a way it should allow the users to select only contacts. Add defaultcustomer at onload event of the form.



function defaultcustomer(){
    Xrm.Page.getControl("customerid").addPreSearch(addFilter);
}
function addFilter()
{
    var customerAccountFilter = "Use following filter here";
    Xrm.Page.getControl("customerid").addCustomFilter(customerAccountFilter, "account");
    Xrm.Page.getControl("customerid").getAttribute().setLookupTypes(["contact"]);
}


Filter: use following filter after removing internal double quotes.
"<"filter type='and'">""<"condition attribute='accountid' operator='null' "/>""<"/filter">"

~Good Luck~