![How to dynamic filtering lookup fields in Microsoft dynamics CRM](images/How-to-dynamic-filtering-lookup-fields-in-Microsoft-dynamics-CRM.jpg)
DESCRIPTION
In this blog, we will learn how we can dynamically filter lookup columns in Dynamics 365 Customer-Engagement based on a selected choice (option) in an option-set field. Consider an option-set called Contact Type having the following options (choices). The Parent Contact and Account Name (Parent Company) lookup fields must be filtered as per the following table.
S.No. | Contact Type Option | Account Type Option | Integer Value |
---|---|---|---|
1 | Family Member | Support Staff | 100000000 |
2 | Franchise Contact | Franchise Unit | 100000001 |
3 | Vendor Contact | Vendor | 100000002 |
We’ll make use of the addPreSearch and addCustomFilter JS functions to achieve the above programmatically.
STEPS
1. We create a new JavaScript Web-Resource with the following code.
2. Add this library function On-Load of Contact main form and On-Change of Contact Type Field.
![Microsoft dynamics CRM](images/Microsoft-dynamics-CRM.jpg)
UNIT-TESTING
1. When Contact Type is Family Member:
Parent Contact Lookup
![Microsoft dynamics CRM1](images/Microsoft-dynamics-CRM1.jpg)
Account Name Lookup
![Microsoft dynamics CRM2](images/Microsoft-dynamics-CRM2.jpg)
2. When Contact Type is Franchise Contact:
Parent Contact Lookup
![Microsoft dynamics CRM3](images/Microsoft-dynamics-CRM3.jpg)
Account Name Lookup
![Microsoft dynamics CRM4](images/Microsoft-dynamics-CRM4.jpg)
3. When Contact Type is Vendor Contact:
Parent Contact Lookup
![Microsoft dynamics CRM5](images/Microsoft-dynamics-CRM5.jpg)
Account Name Lookup
![Microsoft dynamics CRM6](images/Microsoft-dynamics-CRM6.jpg)
Conclusion
Thus, by Microsoft dynamics CRM development making use of the addPreSearch and addCustomFilter JS functions, we succeeded in developing a mechanism to dynamically filter the Parent Contact and Parent Company lookups based on the selected Contact Type option.