Kaizen #91: Dynamic Lookup filters using Client Script

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.
Cheers!



    Access your files securely from anywhere

        Zoho Developer Community







                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now