Filtering and Fixing Lookup field Items

Posted by

Next step from this article, where I did the basic introduction to lookup fields. Now I am moving to filter and fixing of views in a lookup control of a Dynamics CRM form.

Problem Statement – 

From my this View, I want only Leads, which are in Stage2, in my Lookup field. Also I don’t want the user to select any other view to search his record.


but by default in my lookup field, I get all items like this –


Solution –

Step# 1. Filtering the Lookup 

In your JavaScript web resource that is attached to your form, right this code –


FetchXML explanation and variable used here are –

  1. What is my filter type?
  2. Field name in filter criteria. e.g. I want to filter on the basis of stage i.e. aks_stage and this is from my related entity.
  3. What is the value of that field? e.g. In my case, that field was drop down, so I have used its value. if it is some text or any numeric, then it has to be the exact value.
  4. What is my operator? e.g. – eq for equal, ne for not equal and so on…
  5. The closure of filter tag.
  6. aks_filteredLead – this is my field/attribute name where I have employed lookup fields. This control name belongs to my current form control.

If you have some more logic then you add event handler to addPreSearch()  then code will look like this –


Step# 2. Fixing the Lookup views

Go to field properties -> Display -> Additional Properties

Now select OFF from View Selector and you can also assign a new view to fix search results.



Result –

So after both of the above steps, I get this output and it is as expected.



I hope this helps you, in your project scenario.


Happy Dynamics’ing !!!


References –



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s