Client Script: Enforcing Weekly Patient Visit Scheduling Validation in Zoho CRM

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:
  1. Data Accuracy 
  2. Continuous Monitor on Patient
  3. Mitigated Risk
  4. Reduce manual effort
Info

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

  1. //fetching all weeks scheduled visit for patient
  2. console.clear();
  3. var week1_value = ZDK.Page.getField("Week_1").getValue();
  4. var week2_value = ZDK.Page.getField("Week_2").getValue();
  5. var week3_value = ZDK.Page.getField("Week_3").getValue();
  6. var week4_value = ZDK.Page.getField("Week_4").getValue();
  7. var week5_value = ZDK.Page.getField("Week_5").getValue();
  8. var week6_value = ZDK.Page.getField("Week_6").getValue();
  9. var week7_value = ZDK.Page.getField("Week_7").getValue();
  10. var week8_value = ZDK.Page.getField("Week_8").getValue();
  11. var week9_value = ZDK.Page.getField("Week_9").getValue();
  12. var week10_value = ZDK.Page.getField("Week_10").getValue();


  13. //creating a empty array to store each week data
  14. let weekarray = [];

  15. const week1 = {
  16.     "Week": week1_value
  17. }
  18. weekarray.push(week1);

  19. const week2 = {
  20.     "Week": week2_value
  21. }
  22. weekarray.push(week2);

  23. const week3 = {
  24.     "Week": week3_value
  25. }
  26. weekarray.push(week3);

  27. const week4 = {
  28.     "Week": week4_value
  29. }
  30. weekarray.push(week4);

  31. const week5 = {
  32.     "Week": week5_value
  33. }
  34. weekarray.push(week5);

  35. const week6 = {
  36.     "Week": week6_value
  37. }
  38. weekarray.push(week6);

  39. const week7 = {
  40.     "Week": week7_value
  41. }
  42. weekarray.push(week7);

  43. const week8 = {
  44.     "Week": week8_value
  45. }
  46. weekarray.push(week8);

  47. const week9 = {
  48.     "Week": week9_value
  49. }
  50. weekarray.push(week9);

  51. const week10 = {
  52.     "Week": week10_value
  53. }
  54. weekarray.push(week10);

  55. console.log("Array length : ", weekarray.length);

  56. var array = weekarray.length - 1;

  57. //iterating to each week using created array and checking if any week skipped beteen scheduled visits
  58. for (i = 0; i < array; i++) {
  59.     current = weekarray[i].Week;
  60.     next = weekarray[i + 1].Week
  61.     console.log("Iteration Count : ", i);
  62.     console.log("Current :", current);
  63.     console.log("Next :", next);
  64.     if (current == null && next != null) {
  65.         ZDK.Client.showAlert("Week can't be skipped ");
  66.         return false;
  67.         break;
  68.     }
  69. }

  1. 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


Idea
-> 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.
AlertTo 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. 

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

Notes
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.



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

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