Kaizen #91: Dynamic Lookup filters using Client Script
Hello everyone!
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 .
- Enter the following script in the Client Script IDE and click save .
var Product = ZDK.Page.getSubform("Product_list").getField("Product_Name"); Product.setCriteria("(Product_Category:equals:"+value+")", { filterOnSearch: true }); |
- Here, based on the value the user selects in the "Product Category" , the Product Name will be displayed by picking the Instruments from Product module where the category is equal to the user selection.
- Here is how the Client Script works.
You should use setCriteria ZDK in order to apply filters for lookup fields in Client Script.
Now, you may wonder what about
Lookup filters of the field properties in layouts, when to use them and what is the difference.
Here is the comparison which shows when to use lookup filters in Client Script!
( Please note that this comparison holds good as on June 2023, there may be updates made to below features )
Lookup filters in field properties | Lookup filters in Client Script |
Use this when you want to apply filters based on entity criteria.
| Use this when you want to apply filter based on user selected field value. |
The filter criteria is specific to the module . i.e The lookup filter will be the same for all the layouts of the module.
| The filter criteria is specific to the layout. i.e The lookup filter will be not be the same for all the layouts of the module. |
Sample use case
You can use this when you want to apply filters where you know the values involved in the criteria like Created Date is Today, List the Accounts where the account Type is 'Supplier', Modified by Logged in user.
| Sample use case You can use Client Script when the criteria depends on user selection like to list the available instruments in the lookup field "Instrument Name" based on the type of Instrument that user selects in the field "Type". |
We hope you found this post useful. We will meet you next week with another interesting topic!
If you have any questions let us know in the comment section.
Click here for more details on Client Script in Zoho CRM.
Related Links
Cheers!
Sticky Posts
Extension pointers for integrating Zoho CRM with Zoho products #8: Upload and manage Zoho Workdrive folders and files from within Zoho CRM
Keeping records on your customers and business prospects is essential for tracking data, conducting follow-ups, and running a business smoothly. When you use two separate applications, and store relevant data in each, checking and tracking data becomes
Extension pointers: Handle cases with personalized solutions using custom actions
In our last post, we detailed the steps involved in creating a custom action and the workflow from the developer and end user's side. Now let's look at a working example of how we can create a custom action and implement it in a Zoho CRM account to make
Extension pointers - Simple yet significant pointers #13: On change of field value for CRM variables
CRM variables provide global access to a variable across an entire extension. They also help in the storage of user-specific data provided by the user at the time of installation, which can later be fetched to perform data functionalities. Additionally,
Extension pointers: Extend end-user benefits and allow personalization by implementing extensions with custom actions
From our earlier post on custom actions, we know that we can create templated actions, share them with end users, and allow them to reuse those actions to achieve personalized outcomes. In this post, we'll look at how custom actions make it easy for users
Extension pointers - Simple yet significant pointers #12: Functions for Zoho CRM extensions
Functions are essential in achieving logical functionality for an extension. You can easily code your functions in Deluge using drag-and-drop tools to meet your requirements. How to create functions for Zoho CRM extensions in Sigma Go to Sigma and select