Client Script: Effective way to handle Data Validation before Lead Conversion in Zoho CRM

Client Script: Effective way to handle Data Validation before Lead Conversion in Zoho CRM

Requirement Overview

A Zoho CRM organization wants to have validation within Lead module for all Contact's mandatory fields before Lead Conversion. i.e. The Business need an easier & best way to validate lead data before Lead Conversion using default "Convert" button in Lead Record Detail Page. 

This ensures that converted contacts are created with all required data (without empty fields) for effective follow-up and nurturing by the sales team.

Permissions & Availability

Info
-> Users with the Manage Extensibility can configure & setup Client Script.
-> Users with the Manage Sandbox permission can manage the sandbox.
  1. Deploy Client Script in various places

Such as

-> On_Load/On_Save/On_Edit of Page, On_Type/On_Change of Field, Subform Events, Blueprint Events, List View Events, etc.
-> Commands/Shortcut Keys (Trigger script from anywhere & anytime in CRM).
-> Custom Button (Recent Enhancement)

NotesPlease refer to the following Help Reference to know more about Client Script Events Details.
  1. To Create Client Script:

You could add Client Script through two ways:

1. Through Setup Page:

Navigate to Setup (⚙️) in Zoho CRM >> Developer Hub >> Client Script >> New Script.


-> Provide a Name & Description appropriate to script

-> Category Details -
  1.       Select Category based on requirement. Module - triggers via Events || Commands - triggers via Command Pallet/Shortcut Keys.
  2.       Choose Module where you want to add script. i.e., Lead, Contact, etc.
  3.       Choose Page to deploy script in specific page. i.e., Create, Edit, Clone, Detail, List, etc.
  4.       Choose Layout. i.e., Standard or Custom layouts.
-> Event Details - 
      Select Event Type - Field Event or Page Event or Subform Event
  1.       Field Event -> Select the Field & Event (i.e., onChange on First Name field).
  2.       Page Event -> Select the Page & Event (i.e., onLoad on Create Page).
  3.       Subform Event -> Select the Subform & Event (i.e., onCellChange).




2. Through Detail/List/Create/Edit/Clone Pages of a Record in Module

-> Choose a desired module in Zoho CRM, and open either the List, Create, Detail, Edit or Clone page of any record in that module. For example, consider the Create Lead page.
-> For Pages (such as Create/Edit/Clone) - In the right-most corner of the page, click Client Script. Then, Add script.
-> The Category details will be pre-populated by the system. Fill in the other details of the client script, such as Name, Description, Event Details of the client script. Further, click next and add your script to the code editor in Client Script IDE. Then click Save and Close.

Add Client Script via Detail Page:


Add Client Script via Different Pages such as List/Create/Edit/Clone:


Use-case

At the initiate stage, when a lead is first captured (ex: through webform, social media, etc.), it may not be practical or necessary to require all necessary fields to be filled immediately. Some fields might be gathered later during the sales process. Once the sales process is done, Lead needs to be converted to a Contact & Account. 

To maintain high data quality and ensure reliable customer communication, the Business has marked few required fields(i.e. Email, Mobile, Address fields, etc.) as mandatory for contact module. This way, contact record will have a complete data for outreach, segmentation, and service delivery.

Now, when a lead is converted to contact, there are scenarios where user has not filled contact's required information in lead record, due to which contact record will not have the enough information to nurture further after conversion. This in result gives incomplete and inconsistent records in Contact module.

Final Outcome - The Business need an easier & effective way to validate lead data before Lead Conversion using default "Convert" button in Lead Record Detail Page.

Why It is Important:
  1. Data Integrity 
  2. Higher Conversion Rates
  3. Improved Lead Flow Efficiency
  4. Faster Sales Engagement

Key Challenges

Validation Rule - Currently, we do not have a validation on Lead Conversion to avoid such conversation. The default Validation Rule feature will work in Create/Edit/Clone/Detail Page, however it would not be implemented in Lead Conversion.

Trigger based on Convert Button - As of now, we do not have a trigger to setup onClick of default buttons (i.e. Convert) to have a validation and throw error(either inline or pop-up error).

Proposed Approaches & Optimal Solution

We have a various alternative ways to avoid such incomplete conversion. Let us explain below:

Workflow Rule - The user could setup a workflow rule on Lead(i.e. on Edit - trigger) based on specific criteria and select an action(Convert) to convert the lead to contact & account with a deal(if needed). However, this would not be feasible as the user is required to update a specific field in every lead to convert the record, and the Business needs to disable the "Convert" button unnecessarily in every profile permission.

Custom Button - The user could setup a custom button on the Lead Record Detail Page and use a custom function to fetch the lead record details. Then, check if the required fields are empty or not, and convert it to a contact & account using the script accordingly. However, this approach might be challenging for users who are not familiar with coding. Again, default convert button needs to be disabled in every profile permission.

Above two alternatives might not be a feasible and easier approach. However, we have an other Optimal solution using Client Script which can be configured on user's end.

Client Script based Solution to implement Validation

The user could setup a Client Script on load of the Lead Detail Page to have a validation and disable/enable the default “Convert” button. Using client script, we could fetch each required field (with value) and check if it is empty or not. If any field is empty, then disable the Convert Button. Else, enable the Convert Button.

Using this approach, it would be a direct action to default ‘Convert’ button and the user could use the direct Client Methods to fetch field value and set the button as disabled/enabled which can be configured by users(with no coding experience).

Configuration

Now, let us create a Client Script on Detail Page of a Lead Module for OnLoad of Page trigger. As an example, whenever the record detail page loaded, the client script will be triggered and set the action to Convert button based on field data validation.



The Code

  1. console.clear();
  2. manadatoryNotFilled = false;

  3. //Fetching each contact mandatory fields data
  4. var email = ZDK.Page.getField('Email').getValue();
  5. var mobile = ZDK.Page.getField('Mobile').getValue();
  6. var city = ZDK.Page.getField('City').getValue();
  7. var state = ZDK.Page.getField('State').getValue();
  8. var country = ZDK.Page.getField('Country').getValue();
  9. var pin = ZDK.Page.getField('Zip_Code').getValue();
  10. var leadSource = ZDK.Page.getField('Lead_Source').getValue();
  11. // log(email);
  12. // log(leadSource);

  13. //Checking if any field is empty or not
  14. if (email == null || mobile == null || city == null || state == null || country == null || pin == null || leadSource == null) {
  15.     manadatoryNotFilled = true;
  16. }
  17. log("manadatoryNotFilled ---  "+manadatoryNotFilled);

  18. //Fetching Convert button
  19. var convertButton = ZDK.Page.getButton('convert');

  20. //If any field is empty, disabling button. Else, enabling Convert button.
  21. if (manadatoryNotFilled) {
  22.     convertButton.disable();
  23. }
  24. else {
  25.     convertButton.enable();
  26. }

Working Demo - Screencast




This approach is not restricted to check if field is empty or not alone. You could also setup any complex validation in lead fields such as Mobile field(should contain 10 digits) or Email field(should contain a valid domain), before a Lead Conversion.

InfoAs of now, updates performed in the Record Detail Page will not be reflected directly. Instead, users need to refresh the page to view the changes. You could view the following Article which explains how to reflect the change in the detail page automatically.

TIPS

-> Ensure to use the correct API Names for both Module & Fields in the script.

-> While writing the script, we would suggest you to add logs() || console.log() to each variable to check the output for seamless functionality. i.e., you could view the output in the "Messages" tab within Client Script IDE for each logs() print. To view console logs, you could follow - "Right Click on browser page >> Inspect >> Console".

-> In case the expected functionality does not work, then try the script by verifying each output & loop along with that, cross-verify the syntax of each ZDK Client/CRM API method in the provided sample help document. 

-> If you have any repeated lines of script (i.e., repeated small functions), then you could use Static Resources.


InfoSample Scripts for each ZDK Client/CRM APIs methods - Help Reference

To ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to production.



If you need any further clarifications, please don’t hesitate to contact partner-support@zohocorp.com.

Additionally, we kindly ask all Europe and UK Partners to reach out to partner-support@eu.zohocorp.com.

      Create. Review. Publish.

      Write, edit, collaborate on, and publish documents to different content management platforms.

      Get Started Now


        Access your files securely from anywhere

          Zoho CRM Training Programs

          Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

          Zoho CRM Training
            Redefine the way you work
            with Zoho Workplace

              Zoho DataPrep Personalized Demo

              If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

              Zoho CRM Training

                Create, share, and deliver

                beautiful slides from anywhere.

                Get Started Now


                  Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                  BOOK A SESSION







                              Quick LinksWorkflow AutomationData Collection
                              Web FormsRetailOnline Data Collection Tool
                              Embeddable FormsBankingBegin Data Collection
                              Interactive FormsWorkplaceData Collection App
                              CRM FormsCustomer ServiceForms for Solopreneurs
                              Digital FormsMarketingForms for Small Business
                              HTML FormsEducationForms for Enterprise
                              Contact FormsE-commerceForms for any business
                              Lead Generation FormsHealthcareForms for Startups
                              Wordpress FormsCustomer onboardingForms for Small Business
                              No Code FormsConstructionRSVP tool for holidays
                              Free FormsTravelFeatures for Order Forms
                              Prefill FormsNon-Profit
                              Forms for Government
                              Intake FormsLegal
                              Mobile App
                              Form DesignerHR
                              Mobile Forms
                              Card FormsFoodOffline Forms
                              Assign FormsPhotographyMobile Forms Features
                              Translate FormsReal EstateKiosk in Mobile Forms
                              Electronic FormsInsurance
                              Drag & drop form builder

                              Notification Emails for FormsAlternativesSecurity & Compliance
                              Holiday FormsGoogle Forms alternative GDPR
                              Form to PDFJotform alternativeHIPAA Forms
                              Email FormsWufoo alternativeEncrypted Forms
                              Accessible FormsTypeform alternativeSecure Forms

                              WCAG

                                          Create. Review. Publish.

                                          Write, edit, collaborate on, and publish documents to different content management platforms.

                                          Get Started Now






                                                            You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                Manage your brands on social media

                                                                  Use cases

                                                                  Make the most of Zoho Desk with the use cases.

                                                                   
                                                                    

                                                                  eBooks

                                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                                   
                                                                    

                                                                  Videos

                                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                                   
                                                                    

                                                                  Webinar

                                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                                   
                                                                    
                                                                  • Desk Community Learning Series


                                                                  • Meetups


                                                                  • Ask the Experts


                                                                  • Kbase


                                                                  • Resources


                                                                  • Glossary


                                                                  • Desk Marketplace


                                                                  • MVP Corner



                                                                    Zoho Sheet Resources

                                                                     

                                                                        Zoho Forms Resources


                                                                          Secure your business
                                                                          communication with Zoho Mail


                                                                          Mail on the move with
                                                                          Zoho Mail mobile application

                                                                            Stay on top of your schedule
                                                                            at all times


                                                                            Carry your calendar with you
                                                                            Anytime, anywhere




                                                                                  Zoho Sign Resources

                                                                                    Sign, Paperless!

                                                                                    Sign and send business documents on the go!

                                                                                    Get Started Now




                                                                                            Zoho TeamInbox Resources





                                                                                                      Zoho DataPrep Demo

                                                                                                      Get a personalized demo or POC

                                                                                                      REGISTER NOW


                                                                                                        Design. Discuss. Deliver.

                                                                                                        Create visually engaging stories with Zoho Show.

                                                                                                        Get Started Now










                                                                                                                              Wherever you are is as good as
                                                                                                                              your workplace

                                                                                                                                Resources

                                                                                                                                Videos

                                                                                                                                Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                eBooks

                                                                                                                                Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                Webinars

                                                                                                                                Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                CRM Tips

                                                                                                                                Make the most of Zoho CRM with these useful tips.



                                                                                                                                  Zoho Show Resources