Welcome back to another captivating Kaizen post. In this post, we will explore the process of implementing lookup filters using Client Script.
What is a dynamic lookup filter?
A dynamic lookup filter is a feature that allows you to specify conditions or rules for filtering the options displayed in a lookup field based on the values of other fields or related data . It dynamically adjusts the available lookup options to provide a more targeted and relevant selection for users. It enables a more intuitive user experience by presenting only relevant choices based on the user's selections. Not by just using the field value on that page, you can also filter the results of the lookup with current date/time, logged-in user, or any custom condition that you can handle using Client Script. You can achieve this in Create, Edit, Detail (Standard) and Clone pages.
You can apply dynamic filters to the following fields using Client Script.
- lookup fields
- sub-form lookup fields
Use Case 1 -Lookup field filter in a form
Consider a Manufacturing company, ABC. The Admin wants to get the list of accounts that have the Account Type as Vendor for the lookup field name "Linked Account" in the Leads module only for standard layout.
Solution
- Go to Setup > Developer Space > Client Script. Click +New Script.
- Specify the details to create a script and click Next
You can filter the list of Accounts visible in the lookup field using the
ZDK setcriteria() , so that only the accounts of Account Type Vendor will be visible when the user clicks the lookup icon.
- Go to Setup > Developer Space > Client Script. Click +New Script.
- Specify the details to create a script and click Next .
- Enter the following script in the Client Script IDE and click save.
var field_obj = ZDK.Page.getField('Linked_Account'); field_obj.setCriteria("(Account_Type:equals:Vendor)", { filterOnSearch: true }); |
You should use the
ZDK setCriteria along with the filter condition, in order to apply filters.
setCriteria() ZDK
You can view the ZDK Documentations in the Library section of Client Script IDE
Here is how the Client Script works.
Use Case 2 - Dynamic lookup filter in a sub-form
Zylker is a health care company. The Admin wants to list the available instruments in the lookup field " Instrument Name " based on the type of Instrument that a service agent selects in the field "Type" only for standard layout. For example, if the service agent selects the Type as "Surgical Instruments", then he should be allowed to choose only instruments of such type in the subform.
Solution:
- Go to Setup > Developer Space > Client Script. Click +New Script.
- Specify the details to create a script and click Next .