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
-> Users with the Manage Extensibility can configure & setup Client Script.
-> Users with the Manage Sandbox permission can manage the sandbox.
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)
Please refer to the following Help Reference to know more about Client Script Events Details.
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 -
- Select Category based on requirement. Module - triggers via Events || Commands - triggers via Command Pallet/Shortcut Keys.
- Choose Module where you want to add script. i.e., Lead, Contact, etc.
- Choose Page to deploy script in specific page. i.e., Create, Edit, Clone, Detail, List, etc.
- Choose Layout. i.e., Standard or Custom layouts.
-> Event Details -
Select Event Type - Field Event or Page Event or Subform Event
- Field Event -> Select the Field & Event (i.e., onChange on First Name field).
- Page Event -> Select the Page & Event (i.e., onLoad on Create Page).
- 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:
- Data Integrity
- Higher Conversion Rates
- Improved Lead Flow Efficiency
- 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
- console.clear();
- manadatoryNotFilled = false;
- //Fetching each contact mandatory fields data
- var email = ZDK.Page.getField('Email').getValue();
- var mobile = ZDK.Page.getField('Mobile').getValue();
- var city = ZDK.Page.getField('City').getValue();
- var state = ZDK.Page.getField('State').getValue();
- var country = ZDK.Page.getField('Country').getValue();
- var pin = ZDK.Page.getField('Zip_Code').getValue();
- var leadSource = ZDK.Page.getField('Lead_Source').getValue();
- // log(email);
- // log(leadSource);
- //Checking if any field is empty or not
- if (email == null || mobile == null || city == null || state == null || country == null || pin == null || leadSource == null) {
- manadatoryNotFilled = true;
- }
- log("manadatoryNotFilled --- "+manadatoryNotFilled);
- //Fetching Convert button
- var convertButton = ZDK.Page.getButton('convert');
- //If any field is empty, disabling button. Else, enabling Convert button.
- if (manadatoryNotFilled) {
- convertButton.disable();
- }
- else {
- convertButton.enable();
- }
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.
As 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.
To ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to production.