ttajic
5/17/2016 - 10:11 AM

Filter lookup

Filter lookup

function defaultcustomer(){

  Xrm.Page.getControl("customerid").addPreSearch(addFilter);

}

function addFilter()

{
  //show only account (hide contact)

  var customerAccountFilter = "<filter type='and'><condition attribute='contactid' operator='null' /></filter>";
  
  Xrm.Page.getControl("customerid").addCustomFilter(customerAccountFilter, "contact");
}

//Explanation: When you call the defaultcustomer, the system automatically attaches the addFilter method to the search criteria of the lookup control. In the filter condition of the addfilter method, we have mentioned that contactid equals null. contactid can only be null for accounts, as contactid is a primary key for contacts and cannot be null. If you want to display only contacts in the lookup then you can change the condition to be accountid equals null. After adding this script, the user will only be able to select an account in the customer lookup.

//That’s all for the blog today, Remember to subscribe to our blog so that you can stay up to date on all the tips and tricks we post. And as always, happy CRM’ing!