JavaScript function for filtering customer lookups. For example in situations where cases are only created for accounts only. This also prevents contact records from appearing when the user searches in the lookup.
I adapted the code from a blog post from power objects here
AddAccountNamePresearch = function (executionContext) { var formContext = executionContext.getFormContext(); var customerAccountFilter = "<filter type="and"><condition attribute="contactid" operator="null"></condition></filter>"; formContext.getControl("customerid").addPreSearch(function () { formContext.getControl("customerid").addCustomFilter(customerAccountFilter, 'contact'); }); };
If you have multiple customerid controls, for example, one on the form and the other on a BPF, make sure to filter them all by changing the code to the below
AddAccountNamePresearch = function (executionContext) { var formContext = executionContext.getFormContext(); var customerAccountFilter = "<filter type="and"><condition attribute="contactid" operator="null"></condition></filter>"; //add the filters foreach customerid control formContext.getAttribute('customerid').controls.forEach(function (ctrl) { ctrl.addCustomFilter(customerAccountFilter, 'contact'); }); };