Apply Custom Filter on Lookup Field in Dynamics CRM using Script

By | August 20, 2015


In this blog we are going to see how to apply custom filter to the lookup field using the JavaScript functions.

In Microsoft Dynamics CRM we can filter a lookup field on form using the Fetch XML condition and “addPreSearch()“ method.


On the Contact Entity there is a lookup field named “Account Name” and a text field “Address1: City” as shown in below screenshot.custom_filter

So, Here If we want to filter Account records in lookup view by city having value equal to field Address1: City. We can do this by writing the below code in Jscript.

Here we have written two functions “filterLookup()” and “addCustomeLookupFilter()”  as shown in the below code snippets. custom_filter1

We have created CRM webresource for the javascript and called “filterLookup” function on change event for field “Address1: City” field as below for contact entity form.custom_filter2

Function “filterLookup” will be trigger on change of field “Address1: City”. This binds “addPreSearch” event to lookup control “parentcustomerid”.custom_filter3

Open the contact entity record, Before entering the “Address1:City” field value the lookup field shows all the account records as below screenshot.custom_filter4

Enter the value for “Address1: City” here it is “US” as below.custom_filter5

Then Check for the suggested options for the Account lookup. Only those accounts records will be available to select which having city “US”.

Hope this helps!

Need more from Dynamics CRM? Export your Dynamics CRM Reports to Word, Excel or PDF and attach it to Email or Onenote in just one click. Try Click2Export. For more details get in touch with us on

2 thoughts on “Apply Custom Filter on Lookup Field in Dynamics CRM using Script

  1. tdailey77

    Can you help me with the same but on Phone Call form.

    The “Call To” field – we would like to filter that lookup to only show contacts that work for the Account that is in the “regarding” of the Phone Call record. For example, I go to Account ABC and add a phone call activity. The “Call To” lookup when I click on the magnifying glass should only show contacts that work for Account ABC. Possible? Can you show me the code and process to achieve this? Thank you

Leave a Reply