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 –
Step# 1. Filtering the Lookup
FetchXML explanation and variable used here are –
- What is my filter type?
- 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.
- 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.
- What is my operator? e.g. – eq for equal, ne for not equal and so on…
- The closure of filter tag.
- 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.
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 !!!