Using Functions in Client Script

Using Functions in Client Script



Hello everyone!

Welcome back to another interesting Kaizen post. In this post, we can discuss how to invoke Functions using Client Script and how to handle Timeouts in Client Script. This post will answer the question raised in the post, Why Client Script is not running after function execution?


In this Kaizen post,
1. What are Functions in Zoho CRM?
2. How to Invoke a function from a Client Script?
3. Use Case to use existing function in Client Script
4. Solution
5. Timeouts in Client Script
6. How to handle timeouts in a Client Script?
7. Timeout Scenario
8. Solution
9. Summary

1. What are Functions in Zoho CRM?

      Functions in Zoho CRM follows the Serverless Computing architecture. It follows cloud computing execution model in which the cloud provider dynamically manages the allocation of machine resources. Zoho CRM provides options for the customer to write their own functions using Deluge script and run their code ( proprietary within Zoho CRM ) without worrying about deploying their code in servers. Click here to know more about Functions.

2. How to Invoke a Function from Client Script?

      You can invoke a function from a Client Script using the  execute() method. Here is the syntax of execute() method. The Client Script execution will only proceed after the Function has completed, demonstrating synchronous behavior.



3. Use Case to use existing function in Client Script

      Zylker, a manufacturing organization, utilizes Zoho CRM. Within their CRM, there is an existing function sendmailToContactRoles that allows meeting invites to be sent to all contact roles associated with a Deal at the click of a button. Deals often require inputs and approval from various stakeholders. By inviting all contact roles, Zylker ensures that all necessary parties are involved in the decision-making process, reducing delays and improving the chances of closing the deal successfully. To avoid accidental clicks, 
  • The admin wants a confirmation message to appear when the Mail icon is clicked, asking for approval and trigger the Function based on user selection. 
  • Additionally, the admin would like to display a success notification , if the emails are sent successfully.
  • Also, once the email is dispatched, a tooltip saying "Invite Sent" should be added should be added to the Mail icon.

4. Solution

  • Create a Client Script to accomplish the above requirements. Click here to know how to create a Client Script.
  • Create a Client Script for "Deals" module with onClick Event and Icon Event Type for the Detail Page(Canvas).

  • Enter the following code and click Save.
  1. var isProceed = ZDK.Client.showConfirmation('Do you want to invite the Contacts of the Deals', 'Proceed', 'Cancel');
  2. var elem = ZDK.UI.getElementByID('icon');
  3. //If user clicks Proceed button
  4. var deal_rec = $Page.record_id;
  5. if (isProceed) {
  6.  ZDK.Apps.CRM.Functions.execute("sendmailToContactRoles", deal_rec);
  7.  ZDK.Client.showMessage(" All the Contacts have been invited successfully");

  8.  elem.addToolTip({ text: 'Invite Sent' });
  9. }
  10. else {
  11.  elem.addToolTip({ text: 'Click to send invite' });
  12. }

  • After getting user's confirmation with showConfirmation() , the execute() method triggers the function. 
  • The parameters of execute() are function name and parameters
  • The name of the existing function is "sendmailToContactRoles". 
  • The parameters of the function are record ID of the Deal and subject of the email.
  • $Page is a constant supported by Client Script, using which you can get information about the current record. 
  • $Page.record_id will give the id of the current record.
  • Once the function gets executed successfully, you can display the success message using showMessage() . To know more about displaying messages using Client Script , check our Kaizen post Creating Alerts and messages using Client Script.
  • Here is how the Client Script works.

  • Here is the Function code where emailSubject and deal ID are the arguments of this function.
  1. relatedcontrole = zoho.crm.getRelatedRecords("Contact_Roles","Deals",input.dealId.toLong());
  2. emailSubject="Meeting Invite";
  3. emailContent = " Click the following link to join the meeting this evening at 5.00 pm" + " https://meeting.zoho.com/meeting/presenter.do?key=1069852805&cid=5668066&x-meeting-org=53296550";
  4. salutation = "<p>Hello!!<br /><br /></p>";
  5. signature = "<br /><br /><p>Best Regards,<br />Patricia Boyle</p>";
  6. sub = input.emailSubject.toString();
  7. str = input.emailContent.toString();
  8. str = concat(salutation,str);
  9. str = concat(str,signature);
  10. for each role in relatedcontroles
  11. {
  12. emailAddress = role.get("Email");
  13. info emailAddress;
  14. sendmail
  15. [
  16. from :zoho.adminuserid
  17. to :emailAddress
  18. subject :sub
  19. message :str
  20. content type :HTML
  21. ]
  22. }

  • You can achieve the functionality of sending emails in Functions using Client Script itself using fetchRelatedRecords() and  openMailer(). Here, we have made use of the existing Function. 
You can use Functions in Client Script,

To leverage existing Functions for similar functionality, thereby enhancing reusability and to trigger Functions based on UI events such as Icon Event, onType Field Event, Canvas Text Event, and others, beyond the buttons and workflows already supported by Functions.

5. Timeouts in Client Script 

In Client Script, executions are bounded by a 10-second time out. During execution of API calls or during the execution of a function which involves API calls , it might take more than 10 seconds to provide response. Consequently, when they are used in Client Script, execution will get halted. To overcome such scenarios you need to use Loaders.

6. How to handle timeouts in a Client Script?

Client Script allows you to manage the timeout by using a loader. The execution of Client Script will be on hold, as long as the loader is active, and so the timeout will not occur.

a. showLoader()

Use showLoader() to display the loader.



b. hideLoader()

Use hideLoader() to make the loader inactive.



7. Timeout Scenario :

At Zylker, which uses Zoho CRM, there is an existing function named "Books_send_quote" in their Zoho CRM account. The admin wants this function to execute via a Client Script whenever the status is updated to delivered and display a message saying, "Quote has been sent successfully." The admin added the script to show a success message after the function execution. 

Problem :

During execution of the following code, the admin noticed that the code following the function invocation is not running. Similar problem is described in this post.

The current code is 

  1. if (value == Delivered) {
  2. ZDK.Apps.CRM.Functions.execute("Send_Quote");
  3. ZDK.Client.showMessage('Quotation sent successfully', { type: 'success' });
  4. }

In such scenarios, the Messages Pane of Client Script IDE will show Timeout as shown below.



Solution:

 Since the timeout limit of 10 seconds has reached, further execution did not occur. So you need to add ZDK.Client.showLoader() before the execution of the Function and ZDK.Client.hideLoader() after the function execution.

  1. if (value == 'Delivered') {
  2. ZDK.Client.showLoader({type:'page', template:'spinner', message:'Sending Quotation...' });
  3. ZDK.Apps.CRM.Functions.execute("Send_Quote");
  4. ZDK.Client.hideLoader();
  5. ZDK.Client.showMessage('Quotation sent successfully', { type: 'success' });
  6. }
Here is how the Client Script works.



The presence of loader on the screen will inform the user about the ongoing processes in the background.


6. Summary :

This post includes the following,
  • When and how to use Functions in Client Script?
  • How to trigger Client Script using icons?
  • How to add tooltip to an icon using Client Script?
  • How to execute Client Script based on Confirmation box?
  • How to display messages and confirmation box using Client Script?
  • How to add loaders on UI using Client Script?
Previous Post: Kaizen #138 - How are Widgets used inZoho CRM Settings?       |     Kaizen Collection: Home
Join us for our upcoming Zoho CRM Developer Series: Zoho CRM APIs, where you can explore more about Zoho CRM APIs. Register Now!  


    Access your files securely from anywhere



                          Zoho Developer Community




                                                • Desk Community Learning Series


                                                • Digest


                                                • Functions


                                                • Meetups


                                                • Kbase


                                                • Resources


                                                • Glossary


                                                • Desk Marketplace


                                                • MVP Corner


                                                • Word of the Day


                                                • Ask the Experts





                                                          Manage your brands on social media



                                                                Zoho TeamInbox Resources



                                                                    Zoho CRM Plus Resources

                                                                      Zoho Books Resources


                                                                        Zoho Subscriptions Resources

                                                                          Zoho Projects Resources


                                                                            Zoho Sprints Resources


                                                                              Qntrl Resources


                                                                                Zoho Creator Resources



                                                                                    Zoho CRM Resources

                                                                                    • CRM Community Learning Series

                                                                                      CRM Community Learning Series


                                                                                    • Kaizen

                                                                                      Kaizen

                                                                                    • Functions

                                                                                      Functions

                                                                                    • Meetups

                                                                                      Meetups

                                                                                    • Kbase

                                                                                      Kbase

                                                                                    • Resources

                                                                                      Resources

                                                                                    • Digest

                                                                                      Digest

                                                                                    • CRM Marketplace

                                                                                      CRM Marketplace

                                                                                    • MVP Corner

                                                                                      MVP Corner





                                                                                        Design. Discuss. Deliver.

                                                                                        Create visually engaging stories with Zoho Show.

                                                                                        Get Started Now


                                                                                          Zoho Show Resources


                                                                                            Zoho Writer Writer

                                                                                            Get Started. Write Away!

                                                                                            Writer is a powerful online word processor, designed for collaborative work.

                                                                                              Zoho CRM コンテンツ










                                                                                                Nederlandse Hulpbronnen


                                                                                                    ご検討中の方




                                                                                                          • Recent Topics

                                                                                                          • Basic campaign set-up

                                                                                                            I have been trying hard to get Zoho CRM and Zoho Mail connected, but somewhere I seem to have wires loose in my brain. I'm not winning. Could anyone just show me (1) how to set up a scheduled email campaign (test to only six internal staff), (2) how to
                                                                                                          • Add template Categories Qoutes sendmale

                                                                                                            Is there other way to add other template categories in sendmail qoute?
                                                                                                          • What’s New in Zoho Inventory | April 2025

                                                                                                            Hello users, April has been a big month in Zoho Inventory! We’ve rolled out powerful new features to help you streamline production, optimise stock management, and tailor your workflows. While several updates bring helpful enhancements, three major additions
                                                                                                          • Remote Control Functionality During Screen Sharing in Zoho Cliq

                                                                                                            Hello Zoho Cliq Team, We would like to request the addition of remote control functionality during screen sharing sessions in Zoho Cliq. Currently, while screen sharing in Cliq is very useful, it lacks the ability for another participant to take control
                                                                                                          • Report categories not appearing in pie chart

                                                                                                            I have created a simple report to display all of the accounts in our CRM in a certain region, broken down by their 'account type' field. I have displayed this data as a donut chart Highlighted in red in the top left, you can see there are a total of 968
                                                                                                          • Asking for the implementation roadmap or step-by-step guide

                                                                                                            Hello everyone, I'm a freelancer who's been hired to implement Zoho CRM for a client, and I want to make sure I approach this correctly. Could someone kindly share a comprehensive implementation roadmap or step-by-step guide that covers all the essential
                                                                                                          • Custom Function to Format Phone / Mobile numbers in Australian Standard format

                                                                                                            So I got sick of phone numbers being formatted incorrectly and Zoho not doing anything to standardise phone numbers to meet E.164 formats. So I went and coded my own function to fix this. And figured I'd share with the community This is specifically for
                                                                                                          • Sort By Date - Deluge

                                                                                                            I have the following code, which normally works to sort calls by created time. Every once in a while, it doesn't work and something sneaks through in the wrong order and I can't figure out why. calls = zoho.crm.searchRecords("Calls","(Owner:equals:" +
                                                                                                          • Automate Pricebook per Customer

                                                                                                            Example Scenario: I want to create a customer package (Silver Package, Gold Package, Platinum Package) and associated it with a Price Book that contains discounted prices for certain products. When a customer assigned to this Silver Package places an
                                                                                                          • Automate pricebook per customer

                                                                                                            Example Scenario: I want to create a customer package (Silver Package, Gold Package, Platinum Package) and associated it with a Price Book that contains discounted prices for certain products. When a customer assigned to this Silver Package places an
                                                                                                          • Automatic needs analysis for the Deals module

                                                                                                            Good day, I need to get the following functionality in the Deals module: 1. add a Analysis of Customer Needs (ACN) to each transaction 2. the ACN must have a unique number, preferably automatic 3. the ACN must link to the Deal 4. the ACN is completed
                                                                                                          • Color of Text Box Changes

                                                                                                            Sometimes I find the color of text boxes changed to a different color. This seems to happen when I reopen the same slide deck later. In the image that I am attaching, you see that the colors of the whole "virus," the "irology" part of "virology," and
                                                                                                          • Community Digest Noviembre 2024 - Todas las novedades en Español Zoho Community

                                                                                                            ¡Hola, Español Zoho Community! Wow, ya termina el año, ¡gracias a vuestra participación se nos ha pasado volando! Por eso mismo estamos preparando sorpresas para todos los que participáis en la Español Zoho Community para el próximo año, ¡estad atentos
                                                                                                          • Add picklist in subform lookup

                                                                                                            Hello, I am trying to rewrite a script that works on a from as parent form, to the same form when is is a subform. Here is what I did in the form itself : RefCat = Offre_de_produits.distinct(Categorie_OFFRE); clear Categorie_LIGNE; for each Record in
                                                                                                          • Odd differential in Accounting and Physical Stock

                                                                                                            Hi there, Around six months ago we noticed that there was an error in one of our product's stock values. Despite seemingly having no outwards requests unfufilled for this item (I.E, no stock committed any longer at the moment), Accounting Stock is -1
                                                                                                          • Footer in PDF template doesn't stay at the bottom of the page

                                                                                                            When setting up a PDF template there is an option for a header / footer. The header stays at the top of the page however the footer does not. It appears the footer actually serves no purpose as it seems to rise up to underneath the header (see image). Is there a way to lock the footer to the bottom of the page? Otherwise what is the point of it? Image demonstrating what I mean. https://ibb.co/cJY1xZ4
                                                                                                          • Integración Books para cumplir la ley Crea y Crece y Ley Antifraude (VeriFactu)

                                                                                                            Hola: En principio, en julio de 2025, entra en vigor la ley Crea y Crece y Ley Antifraude (VeriFactu). ¿Sabéis si Zoho va a cumplir con la ley para cumplir con la facturación electrónica conectada a Hacienda? Gracias
                                                                                                          • 7008 Request rate limit exceeded. Please retry again later.

                                                                                                            Hello, I'm encountering an issue with the request limit for my function calls. The function is triggered whenever a new record is created, and in many cases, we create these records in bulk (around 50 at a time). For each record, a workflow is initiated
                                                                                                          • At transaction level Discounts for Zoho books UAE version

                                                                                                            Dear Team, Please add transaction level Discounts for Zoho books UAE version. I have been requesting Zoho team past 3 years, Transaction level Discounts is a mandatory option required for our business needs. Zoho books Indian version has the option then
                                                                                                          • No sync

                                                                                                            I have amended a note on my PC, startet syncing but on the smart phne sync starts und runs for minutes. The note amendment ist not shown, but when I go to version the new version is shown but not possibility to accepte the new version
                                                                                                          • Input list of records in Lookup

                                                                                                            Salut, I have 2 scripts that input list of records in a lookup. The first on works fine, the second one doesn't and I do not know why. The only differences, is that the first one input in a lookup a list of records from an actual lookup field, and with
                                                                                                          • How to validate Rich Text in Zoho Creator! Urgent!

                                                                                                            Hi members, Recently I just started to use Rich Text field. Now I have a requirement where I need to validate to ensure this Rich Text field must contain a value. Meaning must contain something. I use the below script if(input.Rich_Text == null) { alert
                                                                                                          • Sharing shreadsheets

                                                                                                            My wife and I each have zoho accounts. If She creates a spreadsheet and shares it with me using my email that is associated with my account, zoho shows a warning that I do not have a zoho account and the only way I can access this file is via the link
                                                                                                          • run a macro on a contact that bounced from crm email merge

                                                                                                            how would one run a macro on a contact that bounced from crm email merge? how would i tell zoho to run a macro that SIGNALS said bounced?
                                                                                                          • iOS 18 is here! Discover the enhanced Bigin app with iOS 18, iPadOS 18 and macOS Sequoia.

                                                                                                            Hello, everyone! We are excited to be back with new features and enhancements for the Bigin app. Let us take a look at the new iOS 18 and iPadOS 18 features. The following is the list of features covered in this update: Control widgets. New app icons.
                                                                                                          • Tip #34- How to Configure Proxy Settings for Unattended Access in Zoho Assist- 'Insider Insights'

                                                                                                            Hey Zoho Assist Community! For those using Zoho Assist's Unattended Access feature, you may come across a need to configure your device through a proxy server. This setup is particularly useful if your network requires strict proxy configurations for
                                                                                                          • The 3.1 biggest problems with Kiosk right now

                                                                                                            I can see a lot of promise in Kiosk, but it currently has limited functionality that makes it a bit of an ugly duckling. It's great at some things, but woeful at others, meaning people must rely on multiple tools within CRM for their business processes.
                                                                                                          • Autoresponders in Zoho CRM will be discontinued—transition to Cadences for enhanced engagement

                                                                                                            Zoho CRM’s Autoresponder feature will be discontinued by September 30, 2025. If you're currently using Autoresponders to automate email follow-ups, we recommend switching to Cadences, a more powerful, flexible, and multi-channel engagement tool for today's
                                                                                                          • GCLID arrives not in CRM with iframe integrated ZOHO Form

                                                                                                            Hello amazing community, I enabled Adwords integration in ZOHO CRM. I have a ZOHO Form integrated in a wordpress. I tested iframe and Javascript. I enabled the "handover" GCLID in the ZOHO Form. When I add a GLID with http://www.example.com/?gclid=TeSter-123.
                                                                                                          • Unified customer portal login

                                                                                                            As I'm a Zoho One subscriber I can provide my customers with portal access to many of the Zoho apps. However, the customer must have a separate login for each app, which may be difficult for them to manage and frustrating as all they understand is that
                                                                                                          • Let's Take Custom Slideshow A Step Further!

                                                                                                            Zoho Show comes with this useful feature called Custom Slideshow. It is, as implied by the name, a feature for slideshowing. I would argue it is a waste to use the feature just for slideshowing. For a custom slideshow, you define a subset of slides. Of
                                                                                                          • Simple Text Search Function

                                                                                                            Would it be too much to ask for a simple text search function? My slide decks are often simply collections of slides of a random over, and I often have to find the slide I need at a moment's notice. A text search function, no matter how rudimentary, would
                                                                                                          • Free webinar alert! Empower Customer Experience in a Changing World with Zoho Desk and Zoho Workplace

                                                                                                            Hello Zoho Workplace Community! We’re back with another exciting webinar—and this time, it’s all about delivering exceptional customer experiences. Join us for "Empower Customer Experience in a Changing World with Zoho Desk and Zoho Workplace," where
                                                                                                          • Copy Address button customisation

                                                                                                            Hi I'm very new to Zoho CRM and need some help regarding Addresses - specifically in relation to the "Copy Address" buttons available within the Contacts and Potentials edit screens.   The majority of my Leads will have both a Mailing Address and a Physical street Address that I need to capture at Lead creation stage.   On conversion of the Lead (to Contact/Account and Potential) I need the following to occur:   In Potentials I need to display ·         Physical Address only   In Accounts I need
                                                                                                          • Add Ability to Set Full Name When Inviting Users to Private Client Portals

                                                                                                            Hi Zoho Creator Team, We hope you're doing well. We’d like to request a usability improvement for client portal invitations in Zoho Creator. When setting up a client portal with the "Private" Portal Type (where only users invited by the admin can access
                                                                                                          • email address issue

                                                                                                            Hi! I am start using zoho to start my company's email marketing campaign, but I can not send the email because is showing that Your email address is already configured as a sender address in another account. But I created a new business email address
                                                                                                          • Can Zia summarize fields?

                                                                                                            A great use case of AI for me would be summarizing company descriptions. We often get long winded descriptions from databases or scraping websites, then reduce them to a couple of sentences stating what a company actually does. Is there any way within
                                                                                                          • Difference between the file extensions .zdoc and .zwriterlink

                                                                                                            I am using Workdrive TrueSync on my windows pc to open files directly from my windows without having to open them from the workdrive web. But, I found something strange, I also have the zoho writer app installed on my windows and if I create a document
                                                                                                          • Deluge should permit a connection to be set with a variable

                                                                                                            Hello, Being one who occasionally likes to post code in the forums, I try to make anything that the end user needs to define be present at the very top of the script so that those who want to implement the script won't have to hunt through lines of code,
                                                                                                          • Create project (flow) and assign to person without account (company)

                                                                                                            Hi Zoho Support & Community, I'm trying to automate a process using Zoho Flow to create a Zoho Project and link it directly to a Zoho CRM Contact. This reflects our B2C workflow where we primarily deal with individual Contacts, not Companies/Accounts.
                                                                                                          • Next Page