Client Script: How to update in Record Detail Page with One-Time Auto Refresh for OnLoad scripts

Client Script: How to update in Record Detail Page with One-Time Auto Refresh for OnLoad scripts

Requirement Overview

A Zoho CRM user is using a Client Script to update records in the detail page. However, users often face challenges when updating fields or subforms on the Record Detail Page using default methods. Also, a sales representative updates a Lead record in Detail Page, which triggers a Client Script that modifies associated fields (e.g., status, owner, or a custom score field). However, the updated values do not appear instantly on the Record Detail Page. This causes confusion or delays in decision-making.

Current Challenges

Updating a Record in Detail Page - As of now, we do not support setValues() Client method for field updates in the Detail View page using the Client Script feature. The same applies for insetRows() Client method which updates Subform.

      Instead, currently we support the mentioned Client methods in other Pages such as Create/Edit/Clone. For Detail View Page, users could use Web API methods (i.e., CRM API) within the client script itself.

How Updates are Reflected in the Record Detail Page - Currently, updates performed in the Record Detail View will not be reflected directly. Instead, users need to refresh the page to view the changes. To overcome this, the user could use navigateTo() Client method in script to provide an automatic navigation to the current record detail page.

Rare Scenario of Automatic refresh loop for OnLoad scripts - Often users configure a Client Script in Detail Page based onLoad Page event and wants the changes to be reflected automatically. However, this creates an automatic loop of page refresh. 

Permissions & Availability

Info
-> Users with the Manage Extensibility can configure & setup Client Script.
-> Users with the Manage Sandbox permission can manage the sandbox.
  1. Deploy Client Script in various places

Such as

-> On_Load/On_Save/On_Edit of Page, On_Type/On_Change of Field, Subform Events, Blueprint Events, List View Events, etc.
-> Commands/Shortcut Keys (Trigger script from anywhere & anytime in CRM).
-> Custom Button (Recent Enhancement)

NotesPlease refer to the following Help Reference to know more about Client Script Events Details.
  1. To Create Client Script:

You could add Client Script through two ways:

1. Through Setup Page:

Navigate to Setup (⚙️) in Zoho CRM >> Developer Hub >> Client Script >> New Script.



-> Provide a Name & Description appropriate to script
-> Category Details -
  1.       Select Category based on requirement. Module - triggers via Events || Commands - triggers via Command Pallet/Shortcut Keys.
  2.       Choose Module where you want to add script. i.e., Lead, Contact, etc.
  3.       Choose Page to deploy script in specific page. i.e., Create, Edit, Clone, Detail, List, etc.
  4.       Choose Layout. i.e., Standard or Custom layouts.

-> Event Details - 
      Select Event Type - Field Event or Page Event or Subform Event
  1.       Field Event -> Select the Field & Event (i.e., onChange on First Name field).
  2.       Page Event -> Select the Page & Event (i.e., onLoad on Create Page).
  3.       Subform Event -> Select the Subform & Event (i.e., onCellChange).




2. Through Detail/List/Create/Edit/Clone Pages of a Record in Module

-> Choose a desired module in Zoho CRM, and open either the List, Create, Detail, Edit or Clone page of any record in that module. For example, consider the Create Lead page.
-> For Pages (such as Create/Edit/Clone) - In the right-most corner of the page, click Client Script. Then, Add script.
-> The Category details will be pre-populated by the system. Fill in the other details of the client script, such as Name, Description, Event Details of the client script. Further, click next and add your script to the code editor in Client Script IDE. Then click Save and Close.

Add Client Script via Detail Page:



Add Client Script via Different Pages such as List/Create/Edit/Clone:


Use-case

A Bank loan officer opens a Lead record in the Detail View Page within Zoho CRM. Based on the selected Loan Type, the system should, Auto-populate the Loan Statue field to "In Review". All of this should happen without needing to save manually or reload the page. 

Configuration

Now, let us create a Client Script on Detail Page of a Lead Module for OnLoad of Page trigger. As an example, whenever the record detail page loaded, the client script will be triggered and set the action to make an update in the record.


Add two Picklist fields - Loan Type & Loan Status. Also, to avoid an automatic refresh loop in the Detail Page, add a custom checkbox field (e.g., name - ForDetailPage_stop_automatic_reload).



Notes
Note : Currently, any updates made to the Detail Page through Client Script do not reflect immediately; the user must reload the page to see the changes applied to the record.

Due to the above limitation, we will automatically refresh the record Detail page using same Client Script so that whenever a user opens a record Detail Page, the script will update the record and make an automatic reload. However, we will have to stop reloading after once. Hence, we are using an other Checkbox field to stop reload.
Info
If you do not want your users to see the custom field, then you could mark it as hidden(i.e. Don't Show) for all profiles in Field Edit Properties.

The Code

  1. var type = ZDK.Page.getField('Loan_Type').getValue(); //fetching Loan Type field value
  2. log(type);

  3.  //fetching current record data
  4. var recDetail = ZDK.Apps.CRM.Leads.fetchById($Page.record_id);

  5. //checking if type field equals to "Personal Loan". If yes, updating Loan Status field to In Review
  6. if (type == "Personal Loan") {

  7.     //updating Country & checkbox fields in record
  8.     recDetail.Loan_Status = "In Review";
  9.     recDetail.ForDetailPage_stop_automatic_reload = true; 
  10.     var recUpdate = recDetail.__update();
  11.     // log("recUpdate", recUpdate);
  12.     
  13.     //getting checkbox field
  14.     var stopField = ZDK.Page.getField('ForDetailPage_stop_automatic_reload');
  15.     var stopFieldVal = stopField.getValue();
  16.     log("field value - " + stopFieldVal);

  17.     //only when checkbox field is false, then enter inside. If not, skip
  18.     if (stopFieldVal == false) {

  19.         //to refresh the Detail Page automatically after update for one time.
  20.         log("entered");
  21.         ZDK.Client.navigateTo('record_detail', { module: 'Leads', record_id: $Page.record_id });
  22.     }
  23. }

Working Demo - Screencast




TIPS

-> Ensure to use the correct API Names for both Module & Fields in the script.

-> While writing the script, 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. 

-> If you have any repeated lines of script (i.e., repeated small functions), then you could use Static Resources.

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

Alert
To ensure a smooth implementation, we recommend configuring and testing the setup in the sandbox environment before deploying it to production.



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


                                          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