Microsoft Dynamics CRM allows us to filter a lookup field on the 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 the below screenshot;
So, 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;
Function ‘filterLookup’ will be triggered on the change of field ‘Address1: City’. This binds ‘addPreSearch’ event to lookup control ‘parentcustomerid’.
Open the contact entity record, Before entering the ‘Address1:City’ field value the lookup field shows all the account records as below screenshot;
Enter the value for ‘Address1: City’ here it is ‘US’ as below;
Then Check for the suggested options for the Account lookup. Only those accounts records will be available to select which have the city as ‘US’.
Hope this helps!