Client Script: Enforce Non-Overlapping Schedules with Subform Date Validation in Zoho CRM

Client Script: Enforce Non-Overlapping Schedules with Subform Date Validation in Zoho CRM

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.
Alert
Why It is Important:
  1. Prevents Double Booking

  2. Accurate Billing

  3. Better Scheduling Discipline

  4. Improved Patient Experience

  5. Enhances Patient Experience

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

  1. //fetching subform data - visit information
  2. console.clear();
  3. var subform = ZDK.Page.getForm().getValues().Visit_Information;
  4. console.log(subform);
  5. var start = subform[0].Visit_Start_Time;
  6. var end = subform[0].Visit_End_Time;
  7. console.log("start : ", start);
  8. console.log("end : ", end);

  9. //if subform has data, code will proceed into If condition
  10. if (subform.length > 1) {

  11.     for (i = 1; i < subform.length; i++) {
  12.         var new_start = subform[i].Visit_Start_Time;
  13.         console.log("new start : ", new_start);
  14.         var new_end = subform[i].Visit_End_Time;
  15.         console.log("new end : ", new_end);

  16.         n = i + 1;
  17.         console.log("before check");
  18.         console.log("first if ", (new_start > start && new_start < end));
  19.         console.log("second if ", (new_end > start && new_end < end));

  20.         //checking if new visit's start falls between previous slots and prevents record save
  21.         if (new_start > start && new_start < end) {
  22.             console.log("check passed at if ");
  23.             ZDK.Client.showMessage("Start Date at row " + n + " is falling between the start and end date of previous row", { type: 'info' });
  24.             return false;
  25.         }
  26.         else if (new_end > start && new_end < end) {
  27.             console.log("check passed at else if ");
  28.             ZDK.Client.showMessage("End Date at row " + n + " is falling between the start and end date of previous row", { type: 'info' });
  29.             return false;
  30.         }
  31.         var start = new_start;
  32.         var end = new_end;
  33.     }
  34. }

  1. Code Explanation

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


Idea
User can configure the same setup for Others Pages as well.
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.

        Create. Review. Publish.

        Write, edit, collaborate on, and publish documents to different content management platforms.

        Get Started Now


          Access your files securely from anywhere

            Zoho CRM Training Programs

            Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

            Zoho CRM Training
              Redefine the way you work
              with Zoho Workplace

                Zoho DataPrep Personalized Demo

                If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

                Zoho CRM Training

                  Create, share, and deliver

                  beautiful slides from anywhere.

                  Get Started Now


                    Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                    BOOK A SESSION







                                Quick LinksWorkflow AutomationData Collection
                                Web FormsEnterpriseOnline Data Collection Tool
                                Embeddable FormsBankingBegin Data Collection
                                Interactive FormsWorkplaceData Collection App
                                CRM FormsCustomer ServiceAccessible Forms
                                Digital FormsMarketingForms for Small Business
                                HTML FormsEducationForms for Enterprise
                                Contact FormsE-commerceForms for any business
                                Lead Generation FormsHealthcareForms for Startups
                                Wordpress FormsCustomer onboardingForms for Small Business
                                No Code FormsConstructionRSVP tool for holidays
                                Free FormsTravelFeatures for Order Forms
                                Prefill FormsNon-Profit

                                Intake FormsLegal
                                Mobile App
                                Form DesignerHR
                                Mobile Forms
                                Card FormsFoodOffline Forms
                                Assign FormsPhotographyMobile Forms Features
                                Translate FormsReal EstateKiosk in Mobile Forms
                                Electronic Forms
                                Drag & drop form builder

                                Notification Emails for FormsAlternativesSecurity & Compliance
                                Holiday FormsGoogle Forms alternative GDPR
                                Form to PDFJotform alternativeHIPAA Forms
                                Email FormsFormstack alternativeEncrypted Forms

                                Wufoo alternativeSecure Forms

                                TypeformWCAG


                                      All-in-one knowledge management and training platform for your employees and customers.

                                                Create. Review. Publish.

                                                Write, edit, collaborate on, and publish documents to different content management platforms.

                                                Get Started Now




                                                                  You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                      Manage your brands on social media


                                                                        • Desk Community Learning Series


                                                                        • Digest


                                                                        • Functions


                                                                        • Meetups


                                                                        • Kbase


                                                                        • Resources


                                                                        • Glossary


                                                                        • Desk Marketplace


                                                                        • MVP Corner


                                                                        • Word of the Day


                                                                        • Ask the Experts


                                                                          Zoho Sheet Resources

                                                                           

                                                                              Zoho Forms Resources


                                                                                Secure your business
                                                                                communication with Zoho Mail


                                                                                Mail on the move with
                                                                                Zoho Mail mobile application

                                                                                  Stay on top of your schedule
                                                                                  at all times


                                                                                  Carry your calendar with you
                                                                                  Anytime, anywhere




                                                                                        Zoho Sign Resources

                                                                                          Sign, Paperless!

                                                                                          Sign and send business documents on the go!

                                                                                          Get Started Now




                                                                                                  Zoho TeamInbox Resources





                                                                                                            Zoho DataPrep Demo

                                                                                                            Get a personalized demo or POC

                                                                                                            REGISTER NOW


                                                                                                              Design. Discuss. Deliver.

                                                                                                              Create visually engaging stories with Zoho Show.

                                                                                                              Get Started Now








                                                                                                                                    Wherever you are is as good as
                                                                                                                                    your workplace

                                                                                                                                      Resources

                                                                                                                                      Videos

                                                                                                                                      Watch comprehensive videos on features and other important topics that will help you master Zoho CRM.



                                                                                                                                      eBooks

                                                                                                                                      Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho CRM.



                                                                                                                                      Webinars

                                                                                                                                      Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                      CRM Tips

                                                                                                                                      Make the most of Zoho CRM with these useful tips.



                                                                                                                                        Zoho Show Resources