Requirement Overview
A Zoho CRM user wants to have an Error Pop-up Validation based on Date fields in a Subform. i.e. A new ‘Start Time’ should not fall between any existing visit's Start and End time for a record.
Use-case
In an Healthcare (i.e. Hospital), each patient visit is scheduled with a Start Time and End Time inside a subform. i.e. Each row represents a single visit slot.
There are scenarios, where users unknowingly enter an incorrect Start Time for the next scheduled visit, which falls between previous booked slots.
To mitigate this risk, an error pop-up mechanism is implemented via Client Scripts in the CRM interface. This ensures to notify CRM user before saving the record and avoids any incorrect data (i.e. scheduled visits) for Patients.
This validation ensures that every visit has a clear, conflict-free time slot, which is critical for smooth operations, billing accuracy, and customer satisfaction.
Why It is Important:
Prevents Double Booking
Accurate Billing
Better Scheduling Discipline
Improved Patient Experience
Enhances Patient Experience
Permissions & Availability
-> Users with the Manage Extensibility can configure & setup Client Script.
-> Users with the Manage Sandbox permission can manage the sandbox and test this use-case.
Configuration
Now, let us create a Client Script on Edit Page of a Patients Module for a Save Button. As an example, whenever the user clicks on Save Button, script will check the subform data, and it will throw an error Pop-up if the new visit's Start Time falls between previous scheduled slots.
Follow the steps below to configure the Client Script for this use case:
1) Provide the basic information, like Name and Description based on script purpose.
2) In the Category Details section, please choose the following:
* Category as Module.
* Page as Edit.
* Module as Patients.
* Choose the required Layout.
3) In the Event Details section, please choose the following:
* Type as a Page Event.
* Event as onSave.
The Code
//fetching subform data - visit information
console.clear();
var subform = ZDK.Page.getForm().getValues().Visit_Information;
console.log(subform);
var start = subform[0].Visit_Start_Time;
var end = subform[0].Visit_End_Time;
console.log("start : ", start);
console.log("end : ", end);
//if subform has data, code will proceed into If condition
if (subform.length > 1) {
for (i = 1; i < subform.length; i++) {
var new_start = subform[i].Visit_Start_Time;
console.log("new start : ", new_start);
var new_end = subform[i].Visit_End_Time;
console.log("new end : ", new_end);
n = i + 1;
console.log("before check");
console.log("first if ", (new_start > start && new_start < end));
console.log("second if ", (new_end > start && new_end < end));
//checking if new visit's start falls between previous slots and prevents record save
if (new_start > start && new_start < end) {
console.log("check passed at if ");
ZDK.Client.showMessage("Start Date at row " + n + " is falling between the start and end date of previous row", { type: 'info' });
return false;
}
else if (new_end > start && new_end < end) {
console.log("check passed at else if ");
ZDK.Client.showMessage("End Date at row " + n + " is falling between the start and end date of previous row", { type: 'info' });
return false;
}
var start = new_start;
var end = new_end;
}
}
-> Script will fetch the current record’s subform data and get the first row Start & End time value. Then, it will check if subform has data. If yes, it will proceed further.
-> Then, it will fetch the same subform fields (Start Time & End Time) value of next rows.
-> Then, it checks if last row Start Time - falls between any previous slots (i.e. previous rows).
-> If incorrect slot found - then it shows the error popup in UI to proceed further by end user. It will also prevent the record save action and still be in Edit Page to correct the data before saving record again.
Popup Error Message - Start Date at row 4 is falling between the start and end date of previous row
Working Demo - Screencast
User can configure the same setup for Others Pages as well.
To ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to production.