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




                                      Zoho Desk Resources

                                      • Desk Community Learning Series


                                      • Digest


                                      • Functions


                                      • Meetups


                                      • Kbase


                                      • Resources


                                      • Glossary


                                      • Desk Marketplace


                                      • MVP Corner


                                      • Word of the Day



                                          Zoho Marketing Automation


                                                  Manage your brands on social media



                                                        Zoho TeamInbox Resources

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

                                                                                                  • How to send binary data in invokeurl task?

                                                                                                    Hello, I am using Adobe's Protect PDF API. Source: https://developer.adobe.com/document-services/docs/overview/pdf-services-api/ Everything works fine in Postman. But for some reason after encrypting the file, it is empty after password protecting the
                                                                                                  • When Email is sent, automatically have information be stored inside.

                                                                                                    Hi there, I just wanted to know if it was feasible to make it so that when i receive an email to a specific email, all of the information or contents would be filled up inside of leads. This will help me with another side of the process that im working
                                                                                                  • can we split the Whatsapp Message (Business Messaging) to only appear to certain user?

                                                                                                    I know that we can split the leads record if a user send a message through Whatsapp API in here as you can see from the image above, we assign two users to handle the messages but it seems to me that all users can see all messages in the 'Message' module
                                                                                                  • Can we customize the default client-facing icons?

                                                                                                    Is there any way to customize the client-facing icons that display in the Zoho Bookings UI?  For example, I'm using the Default page theme and would like to modify the default icon that is shown beside "Service."  The icon currently being shown looks like a baseball hat to me (see attached screenshot) which has no relevance to my business or clients. It would be great if Zoho could provide a different, more generic icon (perhaps a bell icon to represent service?) or better yet allow the icons to
                                                                                                  • Limit excceding issue in zoho creator

                                                                                                    I am transferring data from Zoho Books to Zoho Creator using a Deluge script. However, I am frequently encountering a "limit exceeding error," which seems to be related to the Deluge statements limit. I reached out to Zoho Support, and they informed me
                                                                                                  • ZOho Booking and CRM integration.

                                                                                                    We are using Zoho Booking wiht Zoho CRM in a custom module. Inside our module we use the option to book a meeting with the customer. This part works great we feed the field to the URL and everything work 100%. Now my issue is that I was not able to find
                                                                                                  • [Product update] Instagram Profile Integration with Zoho Analytics

                                                                                                    Dear Customers, We want to inform you about an update affecting the Instagram Profile integration with Zoho Analytics. Meta will deprecate certain metrics from January 8, 2025 as per their announcement in this document. To ensure uninterrupted syncs in
                                                                                                  • Nimble enhancements to WhatsApp for Business integration in Zoho CRM: Enjoy context and clarity in business messaging

                                                                                                    Dear Customers, We hope you're well! WhatsApp for business is a renowned business messaging platform that takes your business closer to your customers; it gives your business the power of personalized outreach. Using the WhatsApp for Business integration
                                                                                                  • Zoho CRM - how to change SuperAdmin

                                                                                                    Hi there - I'm looking for current guidance on how to change the Zoho superadmin for our company - I'm transitioning out of my role and need to delegate to another adminisstrator
                                                                                                  • Translation support expanded for Modules, Subforms and Related Lists

                                                                                                    Hello Everyone!   The translation feature enables organizations to translate certain values in their CRM interface into different languages. Previously, the only values that could be translated were picklist values and field names. However, we have extended
                                                                                                  • Automatic Portal invite

                                                                                                    We have numerous customers we move through a blueprint in deals, when they get to a certain point we need to give them portal access, how can this be done through deluge or a workflow?
                                                                                                  • Pass json to ZDK.Client.openMailer TO parameter

                                                                                                    Hello I try to make send emails to a list of emails with : ZDK.Client.openMailer({ from: 'example@zoho.com', to: details_output, subject: 'test Mailing List', body: 'Test Mailing List Body' }); where details_output is an array like : [{ "email": "testcarte18078@test.com",
                                                                                                  • Create a field in Leads that is displayed in Contacts and Accounts

                                                                                                    I am trying to set it up so that if I create a field "Deals" which I have set up in the Deals module, that any selection made in the Leads module when this is converted to Contact that the selection made under the Deals field in the Leads module will
                                                                                                  • Zoho Analytics in 2024: A look back

                                                                                                    Happy new year to everyone in the Zoho Analytics community! As we welcome 2025, here's a look back of important happenings in 2024.
                                                                                                  • Approval Processes Issue

                                                                                                    Hello, I have a significant issue that could potentially cause serious problems for our company. We have developed a new module that we use as a payment request module. In short, payment requests are made through this module and are approved by different
                                                                                                  • Useful enhancements to Mail Merge in Zoho CRM

                                                                                                    Dear Customers, We hope you're well! We're here with a set of highly anticipated enhancements to the Mail Merge feature in Zoho CRM. Let's go! Mail Merge in Zoho CRM integrates with Zoho Writer to simplify the process of customizing and sharing documents
                                                                                                  • Bulk create tasks - Zoho Projects API

                                                                                                    Hi Zoho/Community, I am trying to create multiple tasks in a single API call, is there a way we can combine multiple request bodies into one single payload? The issue I am facing is the rate limiting on the API, I wanted to create certain amount of tasks
                                                                                                  • Function Needed: Update Account or Contact Profile Image

                                                                                                    Hey there! Zoho doesn't have the ability to automatically populate company logo or contact images once a domain/email is added to a record. This can be done via Clearbit's Logo API: https://clearbit.com/logo  I would like to create a deluge script that
                                                                                                  • Whatsapp Limitation Questions

                                                                                                    Good day, I would like to find out about the functionality or possibility of all the below points within the Zoho/WhatsApp integration. Will WhatsApp buttons ever be possible in the future? Will WhatsApp Re-directs to different users be possible based
                                                                                                  • Mass Email and security

                                                                                                    When I send a mass email to multiple candidates, can they see each other's emails?
                                                                                                  • Context and convenience just got better with Zia's email intelligence

                                                                                                    Dear Customers, We hope you're well! We are in 2024, and email as a tool is only getting more powerful each day. While it enables seamless daily correspondences, we are here with a set of abilities that will enhance your user experience and save several
                                                                                                  • Add home page or dashboard in CRM customer portal

                                                                                                    is it possible to add home page or dashboard in CRM customer portal?
                                                                                                  • Want to upload images to custom image fields using zoho crm api v2.

                                                                                                    Hi i want to upload image to my custom image field from third party application using zoho crm api v2 . Please tell me how i can do this? Thanks
                                                                                                  • Zoho mail stopped receiving emails

                                                                                                    My Zoho email addresses that are linked to a domain suddenly stopped receiving messages yesterday, even though I've been using Zoho mail without problems for 1,5 years. I receive this reply to test emails: "553 Relaying disallowed". Due to this, my SMTP
                                                                                                  • WebDAV / FTP / SFTP protocols for syncing

                                                                                                    I believe the Zoho for Desktop app is built using a proprietary protocol. For the growing number of people using services such as odrive to sync multiple accounts from various providers (Google, Dropbox, Box, OneDrive, etc.) it would be really helpful if you implemented standard protocols such as WebDAV / FTP / SFTP so that alternative inc clients can be used.
                                                                                                  • Download all the Attachment From Document Section Zoho Project

                                                                                                    Hello Team, I hope this message finds you well. I am currently facing an issue while trying to download all the documents associated with a Zoho project. Here’s the scenario: We have more than 150 tasks in a single project. Each task may have documents
                                                                                                  • Is there a way to automatically move a task from a different tasklist to another tasklist when certain criterias are met?

                                                                                                    Hi there, Im new to zoho projects and i was wondering if there was a way to automatically move a task from a tasklist to another tasklist based on criteria such as when the task status is updated to completed and have it move to the tasklist that is named
                                                                                                  • Checklist/ save to onedrive/ a group of items invoicing in Zoho FSM

                                                                                                    hi, is there a way to add a specific checklist to any WO without passing eachtime by the model customization? can we save file such picture directly in our sharepoint ak onedrive? is there any way to add a group of item pre defined to make invoicing easier
                                                                                                  • Creating smart filters manually

                                                                                                    Hi Team, One of my colleagues accidentally deleted the Notification folder in Zoho Mail. Now all the emails are directing to spam instead of inbox. Is there any way to create the smart filter manually?. With Regards, Logeswar V
                                                                                                  • Change Last Name to not required in Leads

                                                                                                    I would like to upload 500 target companies as leads but I don't yet have contact people for them. Can you enable the option for me to turn this requirement off to need a Second Name? Moderation update (10-Jun-23): As we explore potential solutions for
                                                                                                  • Auto-sync field of lookup value

                                                                                                    This feature has been requested many times in the discussion Field of Lookup Announcement and this post aims to track it separately. At the moment the value of a 'field of lookup' is a snapshot but once the parent lookup field is updated the values diverge.
                                                                                                  • Zoho Finance Limitations 2.0 #12: Can't sync Books System Fields (Item Category or Preferred Vendor) to CRM Products. Double entry required

                                                                                                    We add products to Books and sync them to CRM whenever updates are done. However I still have to do double entry because the Books "Item Category" and "Preferred Vendor" fields are not available as options to sync. Scenario Workflow I add a new product
                                                                                                  • Copy across spreadsheets in Zoho Sheet

                                                                                                    Now, you can copy your sheets to other spreadsheets or create a new spreadsheet with them. Not just sheets, copy a cell/range and paste it on any spreadsheet with formats and formulas unchanged. Copy cells/ranges Copy cells/ranges to same/different spreadsheets using Copy & Paste options, or Ctrl+C and Ctrl+V shortcuts. Copy sheet To the same spreadsheet The feature for creating a copy of a sheet in the same spreadsheet is now available as 'Duplicate'. Into a new spreadsheet Want to start a new spreadsheet
                                                                                                  • Rich-text fields in Zoho CRM

                                                                                                    Hello everyone, We're thrilled to announce an important enhancement that will significantly enhance the readability and formatting capabilities of your information: rich text options for multi-line fields. With this update, you can now enjoy a more versatile
                                                                                                  • 100 record view limitation

                                                                                                    I have just migrated from another CRM and am starting in ZOHOcrm with over 5000 contacts. It seems that my searches and sorts are limited to 100 live records....or am I missing something. This seems to be very limiting...in a lot of scenarios (mass email,
                                                                                                  • Used & Non used Inventories

                                                                                                    I have a list of used inventories with campaign names and creation dates. I want to show the count of used and non-used inventories in a dashboard with a date filter (like last 30 days, last 3 months). I’ve written a query for the count, but the date
                                                                                                  • How to search Locked Record?

                                                                                                    Hi, I have script like below, however seems this cannot search those locked record. what para I can add to search locked record? var invoice_info_list = ZDK.Apps.CRM.Invoices.searchByCriteria("(Sales_Order:equals:"+ so_record_id +")");
                                                                                                  • My Zoho Story #8 ネットワイズ フチーロさん:プロジェクト管理から顧客対応までをZoho One で実現

                                                                                                    こんにちは。Zoho コミュニティチームです。 「My Zoho Story」では、Zoho の活用により自社ビジネスを成長させてきた軌跡を、さまざまな業界のユーザーにお聞きします。その経験や知見を、Zoho 活用の幅を広げる参考にしていただきたいと考えています。 今回ご登場いただくジェフリー フチーロさんは、ウェブサイト制作・デザイン、ウェブマーケティングを得意とするデジタルマーケティング会社、株式会社ネットワイズ(netwise)でオペレーションディレクターおよびZoho 運用責任者として活動されています。フチーロさんと同社がどのようにZoho
                                                                                                  • Kiosk Studio wrap-up | How our community used kiosks in 2024

                                                                                                    Hello, everyone! Happy new year! The end of 2024 has been busy, and 2025 promises to be bigger and better. As we ring in the new year, let's rewind and look at Kiosk Studio, our no-code customization tool. The past 300 days have seen the CRM community
                                                                                                  • Getter error message Number of statement execution limit exceed Line:(216)

                                                                                                    Hi, this script is giving me error message "Number of statement execution limit exceed Line:(216)". Please advise htmlpage Pay_Period_Details(PayPeriodID,AgentID,ShowPrint,start_range,end_range) displayname = "Pay Period Details" content <%{ /* Get The current Pay Period Record */ Int_Pay_Period_ID = PayPeriodID.toLong(); Current_Pay_Period_Record = Pay_Period[ID == Int_Pay_Period_ID]; Previous_Pay_Period_ID = thisapp.Application.GetPreviousPayPeriodID(Current_Pay_Period_Record.ID); /* Checking Agent
                                                                                                  • Next Page