Kaizen #194 : Trigger Client Script via Custom buttons

Kaizen #194 : Trigger Client Script via Custom buttons



Hello everyone!

Welcome back to another interesting and useful Kaizen post.

We know that Client Scripts can be triggered with Canvas buttons and we discussed this with a use case in Kaizen#180. Today, let us discuss how to trigger Client Script when a Custom Button is clicked. Using this, you can execute Client Script when a custom button is clicked.

In this post,


1. Event Details 
2. Supported Pages
3. Use Case - Export Subform Rows to Zoho Sheet in a Single Click!
4. Solution
5. Summary
6. Related Links



Client Script support for Custom Buttons opens up possibilities for automation, personalization, and enhanced user interactions in Zoho CRM when a custom button is clicked.
Here is a detailed walkthrough to help you understand it better.

1. Event Details 

The Button event triggers the Client Script when a custom button is clicked. Each time this event is invoked, the context argument is passed to the Client Script. The context contains information about the page from which the button was clicked.


Click here to know more about Client Script Events.

2. Supported Pages

A Custom Button can be placed in different positions based on the Page.


You can add a  custom button in the Util Menu, in Each Record or in the Mass Action Menu of the List Page.


Also, a Detail Page can have a custom button either In Record or in the Related List. Click here for more details about the different possible positions of a custom button.

The following table lists the supported pages and the corresponding context argument, which provides different details based on the page type.


To create a Client Script and make it trigger when a custom button is clicked, first create a Custom button and associate it with a Client Script as shown in the following image.


 Click here to view the steps to create a custom button and configure a Client Script. 

Note:

You can configure the Client Script only from the Buttons page to trigger it when a user clicks a custom button, and not the usual way of Creating Client Script via setup page. Once a script is created, it can be edited and updated from the Client Script setup page

3. Use Case - Export Subform Rows to Zoho Sheet in a Single Click!

Zylker manufactures medical instruments, and its sales representatives frequently need to share bulk order details with distributors and hospital partners using Zoho Sheets. These details such as product names, quantities, and prices are captured in a Subform on the Purchase Order Detail(Standard) Page.
To simplify this, the admin wants to add a custom button called "Export Products" on the Purchase Order Detail Page. When clicked, it should export the Purchase Items from the Subform and move the content to the specified sheet.

4. Solution

To export subform rows to Zoho Sheet with a single click, you can add a custom button to the Detail Page of the record. When clicked, a Client Script will be triggered to fetch the subform data from the Detail Page and pass it to a Function that uses zoho.sheet.createRecords() to insert data into Zoho Sheet.

Here’s how to implement this:

  • Add  “Export Products” custom button on the Detail Page.
  • Add the script to collect subform rows which invokes the Function.
  • Write a Function to create entry in Zoho Sheets  

A. Add “Export Products” custom button on the Detail Page.

  • Go to Setup → Modules and Fields under Customization.
  • Select a Module as Purchase Order.
  • Click on Buttons → Then click + New Button.
  • Enter Button Name and select Action Type as "Client Script"
  • Choose Button Position and Layout details as shown in the following image.
  • Click Create in Configured Client Script, enter the script, and click Add.
  • Select the profiles for which these buttons should be visible.
  • Click Save.



B. Add the Script to collect subform rows and invoke the Function

Use the following Client Script when you configure the custom button.

  1. var casesheetid = ZDK.Client.getInput([{ type: 'text', label: 'Enter the Sheet ID' }], 'Sheet details', 'OK', 'Cancel');
  2. if (casesheetid == null) {
  3.         ZDK.Client.showAlert("Enter the *Case Sheet ID - Import* to import data");
  4.  }
  5. var purchase_items = ZDK.Page.getField('Purchase_items).getValue();
  6. ZDK.Client.showLoader({type: 'page', template:'spinner', message: 'Export in progress, please wait'});
  7. var c=1;
  8. if (sheetid == null) {
  9.     ZDK.Client.hideLoader(); 
  10.     ZDK.Client.showAlert("Enter the *Case Sheet - Export* ID to export data");
  11. }
  12. purchase_items.forEach((r,i) => {
  13.             try {
  14.                resp = ZDK.Apps.CRM.Functions.execute("csvWrite", { "Product_Name": r.Product_Name.name, "List_Price": r.List_Price, "Discount": r.Discount, "Total": r.Total,"Sheetid":casesheetid }); }
  15.             catch (error) {
  16.                 c = 0;
  17.                  ZDK.Client.hideLoader(); 
  18.                 ZDK.Client.showAlert("Unexpected issue occured while adding data in row number "); }
  19.     });
  20.     ZDK.Client.hideLoader(); 
  21.     if (c) {
  22.         ZDK.Client.showMessage("Export completed. Please check the Sheet");
  23.     }
  24.     else
  25.     {
  26.        ZDK.Client.showMessage("Unexpected error "); }}

In this code, several ZDKs are used for various purposes. Click on the ZDK hyperlinks to learn more.


Note

The Client Script you intend to link with the button will be saved only after the custom button is saved.

C. Write a Function to create entry in Zoho Sheets 

  • Go to Setup > Developer Hub > Functions.
  • In the Functions page, click + Create New Function.
  • Choose the category as Button.
  • Click Create.
  • In the Create Function page, enter a name as csvWrite and description for your function.
  • Enter the following function code and click Save.
  1. string standalone.csvWrite(String product,String qty,String up,String amt, String Sheetid){
  2. queryData = Map();
  3. writeData = Map();
  4. header = Map();
  5. writeData.put("Product",product);
  6. writeData.put("Quantity",qty);
  7. writeData.put("Unit_Price",up);
  8. writeData.put("Amount",amt);
  9. SheetData = zoho.sheet.createRecords("Sheetid","Sheet1",writeData,queryData,"sheetconnection");
  10. return SheetData;
  11. }

Click here to know more about zoho.sheet.createRecords().

In the code above:
  • sheetconnection refers to the name of the Zoho Sheet connection, which must have the scopes: ZohoSheet.dataAPI.UPDATE and ZohoSheet.dataAPI.READ.
  • Click here to know how to create a Connection with the required scopes.
  • sheetid is the unique identifier of the Zoho Sheet, available in the sheet’s URL.
  • Sheet1 represents the name of the worksheet (i.e., the tab name shown at the bottom of the Zoho Sheet).
  • Now, when the custom button is clicked, the Client Script is triggered. It prompts for the Sheet ID, fetches the contents of the Purchase Order subform, and invokes a function that writes the content to the Sheet.
Here's how the Client Script works.



5. Summary

In this post we have seen,
  • What is a Button event?
  • How to configure Client Script for a custom button
  • How to write data into Zoho Sheets from Client Script
  • How to create a Function and call it from Client Script

6. Related Links


We are thrilled to be nearing the 200th post in our Kaizen series. As we approach this exciting milestone, we would love to hear from you. Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your input helps us improve and shape the series to serve you better.

Please take a moment to share your thoughts using ✨ this form ✨

We hope you found this post useful!

Happy Client Scripting! 😊

      Zoho Campaigns Resources


        • Desk Community Learning Series


        • Digest


        • Functions


        • Meetups


        • Kbase


        • Resources


        • Glossary


        • Desk Marketplace


        • MVP Corner


        • Word of the Day


        • Ask the Experts


          • Sticky Posts

          • Announcing the new SKILL.md for Zoho CRM and the updated OAS repository!

            We are introducing a new zoho-crm skill to make working with Zoho CRM Developer tools (like APIs, functions, widgets, client scripts, queries etc) easier and faster, with the help of AI in your preferred AI harness like Claude Code, Codex, Cursor, VSCode
          • Kaizen #261 : Using Zoho CRM Skill to generate complex COQL queries

            Hello everyone, In the previous Kaizen posts, we introduced the zoho-crm SKILL.md and discussed how it can help you when you are working with Zoho CRM APIs and Client Script. In this Kaizen, we will focus on using the Zoho CRM `SKILL.md` with GitHub Copilot
          • Kaizen #256 - Build an Arrival Readiness Web Tab in Zoho CRM

            Hi everyone! Welcome back to the Kaizen series! In the post, we discuss a use case in hospitality industry: how an Arrival Readiness web tab widget can be used to let reception staff identify and resolve issues before arrival of guests. Use case In the
          • Kaizen #198: Using Client Script for Custom Validation in Blueprint

            Nearing 200th Kaizen Post – 1 More to the Big Two-Oh-Oh! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
          • Kaizen #226: Using ZRC in Client Script

            Hello everyone! Welcome to another week of Kaizen. In today's post, lets see what is ZRC (Zoho Request Client) and how we can use ZRC methods in Client Script to get inputs from a Salesperson and update the Lead status with a single button click. In this

          Zoho CRM Plus Resources

            Zoho Books Resources


              Zoho Subscriptions Resources

                Zoho Projects Resources


                  Zoho Sprints Resources


                    Zoho Orchestly Resources


                      Zoho Creator Resources


                        Zoho WorkDrive Resources



                          Zoho CRM Resources

                          • CRM Community Learning Series

                            CRM Community Learning Series


                          • Tips

                            Tips

                          • Functions

                            Functions

                          • Meetups

                            Meetups

                          • Kbase

                            Kbase

                          • Resources

                            Resources

                          • Digest

                            Digest

                          • CRM Marketplace

                            CRM Marketplace

                          • MVP Corner

                            MVP Corner




                            Zoho Writer Writer

                            Get Started. Write Away!

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

                              Zoho CRM コンテンツ


                                ご検討中の方

                                  • Recent Topics

                                  • Cash Basis VAT RETURN REPORT Required in Saudi Arabia

                                    Zoho Books in Saudi Arabia not showing TAX RETURNS report on CASH Basis.. It only showing accrual basis. Oforur requirement is both reports (Cash Basis and Accrual Basis ) , same like indian Edition of Zoho Books showing. CASH BASIS RETURN is our Basic
                                  • Tips & Tricks Series - #4 Customize your manual PDF before export

                                    Hello everyone! We’re back again with our Tips & Tricks series. Today, we’ll look at how you can customize your manual PDF before exporting it. With Zoho Learn, you can personalize the exported PDF with options such as headers, footers, colors, and custom
                                  • Digital Marketing Agency: Transforming Your Brand's Online Presence

                                    Imagine trying to build a house on your own without the necessary tools or expertise—it’s overwhelming, right? Digital marketing is the same.
                                  • Introducing Zoho Key Service, a simpler way to access LLMs without API keys

                                    Available in the Professional, Enterprise, and Ultimate editions in the US, IN, AU, JP, and CA DCs. Hello everyone, We are excited to bring Zoho Key Service (ZKS) in Zoho CRM, a simpler way for organizations to access and use third party LLMs. You can
                                  • Reach us through our official support channels

                                    Dear Customers, Thanks a lot for choosing Zoho! Our applications are built to help achieve your day-to-day business goals. We are committed to engaging with you, to understand and develop solutions that enhance your productivity. We are happy and ready
                                  • I cannot add user to my account

                                    I have an account, I deleted a user from the account and I have one unused licence which lasts for 23 days, I tried adding a new user and it said This user is not allowed to add in Zoho. Please contact support-as@zohocorp.com for further details, please
                                  • Domain Activation Issue

                                    I purchased a domain through Zoho, and as I understand it, you were supposed to send me a domain activation link. However, I never received it. As a result, I was unable to activate the domain, and it is now suspended. Because of this, I am not receiving
                                  • Grouping by Stage *type* in widgets

                                    Hi Can I ask for a new feature? I'd like to be able to group by stage type in a Deal widget. That is by whether the Deal is in an Open Stage, a Closed Won Stage, or a Lost stage. Currently I can group by Stage, but if we have 10 open stages and one Closed
                                  • Please release domain bravovietnam.com from an old account

                                    Hello Zoho Support, I am trying to set up Zoho Mail with my domain bravovietnam.com on my account office@bravovietnam.com. Every time I add the domain, I get: "This domain is already associated with this account" — pointing to a DIFFERENT, older account
                                  • ChatGPT Plugin / MCP Server auth error

                                    Hi all I'm trying to connect the ChatGPT plugin for Zoho CRM but after username stage of the auth process, I get this error from the URL https://mcp.zoho.eu/mcp-client/ {"error_description":"Invalid request url, Request is not as per defined in oauth
                                  • Creator -Dynamic addition of Customer Portal User Licenses

                                    Hi, We have a Creator App for B2C about to get released. We are experiencing the Portal User license challenge. Unable to predict the number of users who will download and Subscribe. When a User is about Subscribe and the portal licenses does not exists,
                                  • Need Multiple currency for Suppliers and Buyers

                                    Hello, We need multiple currency support for buyer and suppliers, We are doing international business and we often sell goods in foreign currency as well as local currency, However zoho does not support this, I am trying Free agent and xero they support all currencies for suppliers Bills & expenses as well as buyers invoices, Kindly work on this feature will be great help to decide using zoho books Thank you
                                  • 👍 Zoho CRM's Notes now gets Reactions and a new look

                                    Available in SA and JP DCs. Rolling out to other DCs in phases. Hello everyone, Notes help users capture important updates, collaborate with teammates, and maintain context for records. Now with Note Reactions, users can quickly acknowledge updates, express
                                  • Enhanced Zoho CRM and Office 365 calendar synchronization features!

                                    Dear customers, We're excited to share some significant improvements to our Office 365 calendar synchronization features, aimed at providing you with more control and a more personalized experience. What’s new Choose your Office 365 calendar: During the
                                  • Zoho Books Support

                                    Dear Team, Zoho Books offers a demo before you purchase zoho books. But after that when he actually purchases the product he has to rely on toll free number or help documents. But this might get frustrated in the initial period. Specially in initial period.
                                  • How to add a fee based on payment method

                                    I currently accept both ACH payments and credit card. I want to add a 3% fee to a number of my subscription plans if the customer chooses to use a credit card (and not ACH/checking). How do I do this? Is there an in-built feature, or would i have to create
                                  • What's New in Zoho Invoice | July – September 2026

                                    Hello everyone! We're back with the latest updates and enhancements we've rolled out in Zoho Invoice from July to September 2026. Here's what's new this quarter: Zoho Invoice is Now Available in Nigeria Introducing the Super Admin Privilege E-Invoicing
                                  • Notes - Reaction Buttons

                                    Using the native notes option within CRM is fine, it works and the RTF features are great, however, would it be possible - if there isnt already something in place, where we can add a reactions button, similar to teams/whatsapp to show that its been read
                                  • ZohoBooks - "Account transactions" report doesn't have any "Desciptions"

                                    Hi, I'd like to push for this to be included in ZohoBooks: In a "account transactions" report all the numbers are right, but I'd really like to see the "Description" as part of this report, i.e. the line-item-description as I would see it in the bank statement. Essentially all you see is a list of numbers adding up to the total. It is very difficult to see if things are right without being able to see what exactly each transaction refers to. Going into each transaction one-by-one is not a workable
                                  • Address limits per customer by edition

                                    I’m on the Standard edition and have reached a limit of 30 addresses under a single customer. Before I move to an annual Professional subscription, I need to confirm the following: What is the maximum number of addresses allowed under one contact, and
                                  • Export from List view

                                    I'm constantly having the issue where my users are building lists in ListView for various objects and then realising they cant export the data, then they have to go and build the data set in reports to export. I would like to see the ability to export to excel/csv from ListView.
                                  • Cannot apply tags to multiple items at once

                                    It is very frustrating needing to apply tags to notes individually. Even worse that it takes multiple clicks to do it. Can there please be an update to: 1.) Allow us to apply tags to batches of notes in one go. 2.) Make it less clicks to add a tag 3.)
                                  • Get all hiring updates via Zoho Cliq bot notifications

                                    We’re introducing a new way to stay updated on recruitment activities: Cliq Bot notifications. Now you can receive Zoho Recruit notifications directly in Zoho Cliq—alongside your existing in-app alerts and emails. Whether it’s a candidate status change,
                                  • Notes Acknowledgement

                                    It would be great to have emojis that can be used for Notes. Emojis such as Thumbs Up to let someone know you agree with them or a emoji for thanks. It's a simple way to acknowledge that you read someone's note. Moderation update: Emoji reactions for
                                  • Is it possible to log text messages from iphone into Zoho CRM

                                    My team is more and more utilizing text messaging to communicate with clients. Does Zoho have a solution for logging these text messages when clicking "Send Text Message" from the Zoho app. Much like when you call, you get prompted to log a call, can
                                  • Project Finances: Fully Accessible within Projects

                                    Project finances and work items are now on the same screen and it transforms the way you run your project. Managing your project finances is now much easier and in the same screen as your work items. Access quotes, invoices, bills, sales orders, and purchase
                                  • UI / UX Improvements

                                    Please consider changing the Dependency Details window from a column-based layout to a list-based layout, or allowing users to choose their preferred layout. The current column-based view uses screen space inefficiently and makes navigation difficult,
                                  • Zoho CRM and Desk sandboxes for testing native integration

                                    Hello team, We are evaluating the native integration between Zoho CRM and Zoho Desk, We have sandbox instances of both products and want to test the integration there, without any effect on our production CRM or production Desk data. While setting up
                                  • Function #24: Automatically display deal name from Zoho CRM on quotes in Zoho Books

                                    Deals allow businesses to organize and visualize their sales pipeline. This provides a clear overview of all potential opportunities and helps in making informed decisions. Zoho CRM empowers you to create deals or potentials for your clients and monitor
                                  • Auto-Sync Field of Lookup Values When Parent Record Changes

                                    Hi Zoho Team, Currently, when you use a "Field of Lookup" in Zoho CRM, the value is captured as a snapshot at the time the lookup is set. If the parent record is later updated, the Field of Lookup value on the child record does NOT update and stays stale.
                                  • [Request] Pivot filter date option : from set date to relative value ie from 01Jan to LastMonth

                                    I don't think I can currently do this... but it's worth asking if it's possible. My use case is concerning annual leave which is calculated from the beginning of the calendar year (01Jan) then each month I want to have details of leave taken etc... In
                                  • Customer Statement Showing Incorrect Negative Balance Due to Unused Advance

                                    Dear Zoho Support Team, We are facing an issue with the Customer Statement in Zoho Invoice related to customer advances/mobilization advances. The issue is that when a customer has made an advance payment that has not yet been fully utilized against invoices,
                                  • Mois de la sensibilisation à la cybersécurité 2026 : faites de la sécurité un réflexe avec Zoho

                                    Imaginez : vos systèmes informatiques répondent aux normes de sécurité en vigueur et votre entreprise est assurée contre les cyberattaques. Pourtant, un matin, tout bascule. Vos données sont chiffrées et un message glaçant s’affiche à l’écran : « Si vous
                                  • Specifying time increments on a Date/Time field

                                    Hi all, Im using a Date/Time field in my CRM module. At the moment the increments are 30 minutes. How can I change these to be 15 minutes? Thanks
                                  • What's new in Zoho Workplace | August 2026

                                    Hello Zoho Workplace community! Here's a roundup of all the new features and announcements that went live across Zoho Workplace applications in August. Zoho Mail Zoho Mail is now available in AWS Marketplace! AWS Marketplace users can access and subscribe
                                  • What's new in Zoho Social - Q3 recap

                                    Hello everyone, We've rolled out a bunch of exciting updates in Q3, and we're thrilled to walk you through them. Here's a quick look at everything we released in July, August, and September to help you experiment with content, automate engagement workflows,
                                  • Zoho Books | Product updates | October 2026

                                    Hello users, October brings a range of new features and enhancements to Zoho Books, designed to simplify compliance, streamline accounting workflows, and improve inventory management. From the launch of the Nigeria Edition and France’s e-invoicing capabilities
                                  • The Social Wall: September 2026

                                    Hello everyone! This month, we’re bringing Snapchat to Zoho Social. You can now connect your Snapchat account and manage your content alongside your other social channels. Whether you want to reach a wider audience through Spotlights or share quick updates
                                  • Turning off the recorded welcome in Zoho Webinar

                                    Is there a way to turn off the recorded voice that comes up at the beginning of every webinar session? It devalues the experience for attendees from feedback, interrupting their connection with our brand and delaying webinar start unnecessarily.
                                  • Option to Disable Knowledge Base Section in Feedback Widget Popup Hello Zoho Desk Team

                                    Hello Zoho Desk Team, How are you? We are actively using Zoho Desk and would like to make more use of the Feedback Widget. One of the ways we implement it is through the popup option. At the moment, the popup always displays the Knowledge Base section,
                                  • Next Page