Problem:
The limited number of validation rules with custom functions in Zoho CRM (three in the Enterprise Plan and five in the Ultimate Plan), along with the restriction of triggering only one field per rule, significantly hinders businesses that require extensive data validation and automation. This limitation affects data quality, enforcement of business rules, and process efficiency, making it challenging to maintain accurate and consistent data entries.
Solution:
We can overcome the above problem using client script functions in Zoho CRM. By leveraging client scripts, we can implement custom validation functions to enforce complex validation rules across multiple fields and modules. This solution allows us to ensure consistent data restrictions and maintain high data accuracy. Client scripts provide the flexibility and control needed to enhance data quality and ensure compliance with our data entry standards. Implementing this approach will significantly improve the reliability and integrity of our CRM data.
To understand more about client script, you can refer this URL
Usecase:
One practical example of leveraging client script functions in Zoho CRM is implementing date validation to prevent future dates from being entered in multiple date fields. By using client scripts, we can create a custom validation function that consistently enforces this rule across various modules and fields. This ensures that users adhere to data entry standards, enhancing the accuracy and reliability of our CRM data.
Steps to achieve this:
Open Zoho CRM Settings > Developer Hub > Client Script > New Script.
Select the Category as module , Page as (Edit Page (Standard)), Select the module where you want to execute the client script, Layout as Standard, Event type as Page Event and Event as onsave click next. It will take you to the page where you want to write the code.
- // Define the date fields to be validated
- let dateFields = ['Date_1', 'Date_2', 'Date_3', 'Date_4', 'Date_5', 'Date_6'];
- // Initialize an array to store the field values
- let values2 = [];
- // Loop through each date field to get its value
- for (let i = 0; i < dateFields.length; i++) {
- // Get the value of the current date field
- let fieldValue = ZDK.Page.getField(dateFields[i]).getValue();
-
- // Check if the field value is empty or undefined
- if (!fieldValue) {
- // Assign '0' if the field value is empty or undefined
- fieldValue = '0';
- }
-
- // Log the field value for debugging purposes
- log(fieldValue);
-
- // Add the field value to the values2 array
- values2.push(fieldValue);
- }
- // Log all the collected field values
- log('values' + values2);
- // Function to identify fields with future dates
- function getFutureDateFields(dates, fields) {
- // Get the current date
- let currentDate = new Date();
-
- // Initialize an array to store fields with future dates
- let futureDateFields = [];
- // Loop through the dates array
- for (let i = 0; i < dates.length; i++) {
- // Convert the date string to a Date object
- let date = new Date(dates[i]);
-
- // Check if the date is in the future
- if (date > currentDate) {
- // Add the corresponding field to the futureDateFields array
- futureDateFields.push(fields[i]);
- }
- }
- // Return the array of fields with future dates
- return futureDateFields;
- }
- // Get the fields that have future dates
- let futureFields = getFutureDateFields(values2, dateFields);
- // Log the fields that have future dates
- log('Fields with future dates: ' + futureFields);
- // If there are any fields with future dates, take action
- if (futureFields.length > 0) {
- // Loop through each field with a future date
- for (let i = 0; i < futureFields.length; i++) {
- // Set the value of the field to null
- ZDK.Page.getField(futureFields[i]).setValue(null);
-
- // Make the field mandatory
- ZDK.Page.getField(futureFields[i]).setMandatory(true);
- }
-
- // Show an alert to the user listing the fields that cannot have future dates
- ZDK.Client.showAlert(futureFields.join('\n'), 'Below fields cannot have a future date');
- }
Let us know if any updates, improvements and support in creating similar usecases.