Client Script: Enforcing Weekly Patient Visit Scheduling Validation in Zoho CRM
Requirement Overview
A Zoho CRM user requires a validation mechanism to ensure consistency in scheduling hospital visits. The system should enforce, where users cannot skip any week while scheduling visits to the Hospital.
Use-case
In a Healthcare Clinic, maintaining regular and consistent patient visits is critical for effective treatment, monitoring, and compliance. Many care plans in the Clinic, require patients to visit the hospital on a weekly basis without interruption.
Without a proper validation mechanism in Zoho CRM, users may accidentally skip scheduling visits for certain weeks. This situation can lead to:
Gaps in patient monitoring and treatment continuity
Increased risk of missed diagnoses or delayed care
Inaccurate reporting and poor data quality
Higher dependency on manual tracking by staff
To mitigate this risk, an error pop-up mechanism is implemented via Client Scripts in the CRM interface. This ensures to notify CRM user are immediately notified when they attempt to update a visit information that results in a skipped week.
The system prevents the record from being saved until the scheduling gap is corrected, thereby enforcing adherence to weekly visit requirements.
Why It is Important:
Data Accuracy
Continuous Monitor on Patient
Mitigated Risk
Reduce manual effort
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 any changes in Page. As an example, whenever the user tries to update any data in Edit Page, script will check the weekly visit data, and it will throw an error Pop-up, if there is any skipped visit in the Patients schedule.
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 onChange.
The Code
//fetching all weeks scheduled visit for patient
console.clear();
var week1_value = ZDK.Page.getField("Week_1").getValue();
var week2_value = ZDK.Page.getField("Week_2").getValue();
var week3_value = ZDK.Page.getField("Week_3").getValue();
var week4_value = ZDK.Page.getField("Week_4").getValue();
var week5_value = ZDK.Page.getField("Week_5").getValue();
var week6_value = ZDK.Page.getField("Week_6").getValue();
var week7_value = ZDK.Page.getField("Week_7").getValue();
var week8_value = ZDK.Page.getField("Week_8").getValue();
var week9_value = ZDK.Page.getField("Week_9").getValue();
var week10_value = ZDK.Page.getField("Week_10").getValue();
//creating a empty array to store each week data
let weekarray = [];
const week1 = {
"Week": week1_value
}
weekarray.push(week1);
const week2 = {
"Week": week2_value
}
weekarray.push(week2);
const week3 = {
"Week": week3_value
}
weekarray.push(week3);
const week4 = {
"Week": week4_value
}
weekarray.push(week4);
const week5 = {
"Week": week5_value
}
weekarray.push(week5);
const week6 = {
"Week": week6_value
}
weekarray.push(week6);
const week7 = {
"Week": week7_value
}
weekarray.push(week7);
const week8 = {
"Week": week8_value
}
weekarray.push(week8);
const week9 = {
"Week": week9_value
}
weekarray.push(week9);
const week10 = {
"Week": week10_value
}
weekarray.push(week10);
console.log("Array length : ", weekarray.length);
var array = weekarray.length - 1;
//iterating to each week using created array and checking if any week skipped beteen scheduled visits
for (i = 0; i < array; i++) {
current = weekarray[i].Week;
next = weekarray[i + 1].Week
console.log("Iteration Count : ", i);
console.log("Current :", current);
console.log("Next :", next);
if (current == null && next != null) {
ZDK.Client.showAlert("Week can't be skipped ");
return false;
break;
}
}
Code Explanation
-> Script will fetch the current record’s data and get all the week fields value.
-> Then, it will create an Array (i.e. Bucket) to store each week value.
-> Then, the script will iterate to each element in Array and store current (user updated field) & next week data.
-> If any week is skipped - then it shows the error popup in UI to proceed further by end user.
Working Demo - Screencast
-> User can configure the same setup for Detail Page as well.
-> Also, user can setup this for multiple fields(based on Page Event -> OnChange) on a page to mitigate such data loss risk.
To ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to production.TIPS - Avoid Common Errors
-> Ensure to use the correct API Names for both Module & Fields in the script.
-> To ensure you get the intended output, 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.
Notes: Refer to the following Guide - Article to learn the best practices for Optimizing the code and various ways to deploy Client Script across Zoho CRM.