Today, I met with a requirement where we need to achieve filtering of lookup values based on option set value selection.
The requirement was to filter Loan Category(lookup field), based on Loan Type(optionset field).
There were three different types of Loan Types in the system (optionset field).
- Home Loan
- Business Loan
- Personal Loan
I had to provide the required filter on “Lead” entity. So, below are the steps which I followed.
- Created a Global OptionSet, having Loan Types.
- Created a field Lead Loan Type(blog_leadloantype) of option set type on Lead entity and called the Global Option Set
- Created a field Lead Category(blog_leadcategory) of lookup type on Lead entity. Which have a relationship with one of our custom entity name Bank Code.
- Created a field Loan Type(blog_loantypes) of option set type under Bank Code entity. (required for filtering values)
Below is the screenshot of Bank Code entity, from advanced find which show the data to be filtered in the below desired format.

Create a new webresource of Javascript type and paste the below the code in the editor:
(function () { }(window.BankNotes = window.BankNotes || {})); (function (BankNotesFilter) { BankNotesFilter.onCategoryChange = function (executionContext) { var formContext = executionContext.getFormContext(); //Check if the field is not null if (formContext.getAttribute("blog_leadloantype").getValue() != null) { //Apply Search on lookup field OnClick formContext.getControl("blog_leadcategory").addPreSearch(function(){ var loancode = formContext.getAttribute("blog_leadloantype").getValue(); //Apply the filter condition var filter = "<filter type='and'><condition attribute='blog_loantypes' operator='eq' value='" + loancode + "' /></filter>"; //Populate the filter values into lookup field formContext.getControl("blog_leadcategory").addCustomFilter(filter); }); } }; }(window.BankNotes.BankNotesFilter = window.BankNotes.BankNotesFilter || {}));
The above script will triggered on the onChange event for Lead Loan Type(blog_leadloantype). Function which needs to be called – BankNotes.BankNotesFilter.onCategoryChange
I hope this helps you. 👍