Kaizen #62 - Using field related functions in Client Script

Kaizen #62 - Using field related functions in Client Script

Welcome to another week of Kaizen!
This post is about the Field related functions in Client Script.

Field related functions in Client Script

You can use the ZDK functions to achieve desired actions for various events.

ZDK function
Description
getField
To fetch the field information by api name
getFields
To fetch the list of fields in the Page as an array 
getApiName
To fetch the API name of field
mask
To mask the field value
showError
To show inline error message for an input field
setValue
To set the value for a field
getValue
To get the value of a field
setMandatory
To set the mandatory attribute for the input field
setMaxLength
To set the max length of field input
setReadOnly
To set the read-only attribute of field input

Use Case

ABC is a hardware manufacturing company. Let us consider that you want to achieve the following using Client Script.
  1. In the create page of Order module, whenever the field Product is selected, the field Category
    should get auto-populated based on the following table.    
    Category
    Products
    Ignition system
    Sparking cable, Ignition box, Ignition coil, Spark plug
    Gauges and meters
    Speedometer,Odometer, Voltmeter, Temperature gauge

  2. If the Category is Ignition System, the field Number of Boxes should be mandatory.
  3. If the field Country is India, the maximum number of digits that the user can enter in the field Phone Number should be limited to 10. 
  4. Whenever the user edits or adds the Phone Number with length less than 10, display an error message near the field. 
  5. The last five digits of the Phone Number field value should be masked for all profiles except the Administrator.
Solution using Client Script
The requirements 1-4 are for the create page of Orders module. The 5th requirement is on the detail page of the module Orders. So create two scripts as follows.
  • Client script for create page (requirements 1-4)
  • Client script for detail page (requirement 5).
1. Client Script for create page (covers requirements 1-4)
  • Go to Setup > Developer Space > Client Script. Click +New Script.
  • Specify the details to create a script and click Next.

  • Enter the following script and click save.

 switch (field_name) {
    case 'Product':
        var product_name = ZDK.Page.getField('Product').getValue();
        var category_field = ZDK.Page.getField('Category');
        // requirement - 1
        if (['Sparking cable', 'Ignition box', 'Ignition coil', 'Spark plug'].includes(product_name)) {
            // Populate value for picklist field 'Category' based on the condition
            category_field.setValue("Ignition system");
            ZDK.Page.getField('Number_of_Boxes').setMandatory(true); // requirement - 2
        } else if (['Speedometer', 'Odometer', 'Voltmeter', 'Temperature gauge'].includes(product_name)) {
            // Populate value for  picklist field 'Category' based on the condition
            category_field.setValue('Gauges and meters');
        }
        break;

  case 'Phone_Number':
        var phone_field = ZDK.Page.getField('Phone_Number');
        if (phone_field.getValue().length < 10) {
            phone_field.showError('Enter a valid phone number'); // requirement - 4
        }
        break;

 case 'Country':
       ZDK.Page.getField('Phone_Number').setMaxLength(10);
       break;
    case 'Category':
        if (ZDK.Page.getField('Category').getValue() === 'Ignition system') {
            ZDK.Page.getField('Number_of_Boxes').setMandatory(true); // requirement - 2 when category is changed in ui
        }
        break;

}

  • Here is how the client Script works,


2. Client Script for detail(canvas) page (covers requirement 5)
  • Go to Setup > Developer Space > Client Script. Click +New Script.
  • Specify the details to create a script and click Next.



  • Enter the following script and click save.

  var user = ZDK.Apps.CRM.Users.fetchById($Crm.user.id);
  if (user.profile.name !== 'Administrator') {
    ZDK.Page.getField('Phone_Number').mask({ character: '*', length: 5, reverse: true });
  }



Note: $Crm is a constant supported by Client Script, using which you can get the org related information and use it in your script. 

  • You can see that the Phone Number is partially masked when you view the order canvas page as a Standard User.

  • You can see that the Phone Number is not masked when you view the order canvas page as an Administrator.


We hope you found this post useful. We will meet you next week with another interesting topic!
If you have any questions let us know in the comment section.
Cheers!


Previous Kaizen post: Composite API

    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

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

                                                   
                                                    

                                                  Videos

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

                                                   
                                                    

                                                  Webinar

                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner




                                                            • Sticky Posts

                                                            • Kaizen #197: Frequently Asked Questions on GraphQL APIs

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! 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 #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.
                                                            • Celebrating 200 posts of Kaizen! Share your ideas for the milestone post

                                                              Hello Developers, We launched the Kaizen series in 2019 to share helpful content to support your Zoho CRM development journey. Staying true to its spirit—Kaizen Series: Continuous Improvement for Developer Experience—we've shared everything from FAQs
                                                            • Kaizen #193: Creating different fields in Zoho CRM through API

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! 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.
                                                            • Client Script | Update - Introducing Commands in Client Script!

                                                              Have you ever wished you could trigger Client Script from contexts other than just the supported pages and events? Have you ever wanted to leverage the advantage of Client Script at your finger tip? Discover the power of Client Script - Commands! Commands


                                                            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

                                                                                                            • Help! Unable to send message;Reason:554 5.1.8 Email Outgoing Blocked.

                                                                                                              Kindly help me resolved this issue that i am facing here.
                                                                                                            • How are people handling estimates with Zoho inventory?

                                                                                                              We are often using Zoho Books for estimates that then get converted to invoices within Books. We would like the sales team to migrate entirely to Zoho Inventory and no longer need to use Zoho Books so that they are only on one system. How are people managing
                                                                                                            • Relative Date Searches

                                                                                                              Currently in the search options, it has "date", "from date" and "to date". I think it would be great if there were options like "date greater than x days ago" and "date less than x days ago". I realise that as a once off you can just use the existing
                                                                                                            • Performance is degrading

                                                                                                              We have used Mail and Cliq for about three years now. I used to use both on the browser. Both have, over the past 6 months, had a severe degradation in performance. I switched to desktop email, which appeared to improve things somewhat, although initial
                                                                                                            • Ask the Experts 23: Customize, utilize, and personalize with Zoho Desk

                                                                                                              Hello everyone! It's time for the next round of Ask the Experts (ATE). This month is all about giving Zoho Desk a complete makeover and making it truly yours. Rebrand Zoho Desk with your organization’s details, customize ticket settings based on your
                                                                                                            • Dear Zoho CEO: Business Growth is about how you prioritise!

                                                                                                              All of us in business know that when you get your priorities right, your business grows. Zoho CRM and Zoho Books are excellent products, but sadly, Zoho Inventory continues to lag behind. Just this morning, I received yet another one-sided email about
                                                                                                            • Payroll In Canada

                                                                                                              Hi, When can we expect to have payroll in Canada with books 
                                                                                                            • Please review and re-enable outgoing emails for my domain

                                                                                                              Hello Zoho Support, I have recently purchased a new domain and set up email hosting with Zoho. However, my account shows "Outgoing Email Blocked". I am a genuine user and not sending bulk/spam emails. Please review and re-enable outgoing emails for my
                                                                                                            • Payroll without tax integrations (i.e. payroll for international)

                                                                                                              It seems as though Zoho waits to develop integrations with local tax authorities before offering Zoho Payroll to Zoho customers in a country. Please reconsider this approach. We are happy Zoho Books customers, but unhappy that we have to run payroll in
                                                                                                            • goingout e mail block

                                                                                                              info@ozanrade.com.tr
                                                                                                            • Incoming mails blocked

                                                                                                              Zoho User ID : 60005368884 My mail Id is marketing#axisformingtechnology.com .I am getting following message "Your Incoming has been blocked and the emails will not be fetched in your Zoho account and POP Accounts. Click here to get unblocked." Please
                                                                                                            • Assistance Needed: Ticket Status Not Updating and Sorting by Last Customer Reply in Zoho Desk

                                                                                                              Hello, I’m facing two issues in Zoho Desk that I’d like your guidance on: Ticket Status Not Updating: When a customer replies to a ticket, the status does not change to Reopened. Instead, it remains in Waiting on Customer, even after the customer’s response
                                                                                                            • Configuring Email Notifications with Tautulli for Plex

                                                                                                              Hi I'm new to Zoho. I am from Canada and I have a I use a web based application called Tautulli for Plex that monitors my Plex media server. It also sends a newsletter to my followers. To set this up they require a "From" email address., a smtp server
                                                                                                            • ME SALE ESTE ERROR: No fue posible enviar el mensaje;Motivo:554 5.1.8 Email Outgoing Blocked

                                                                                                              Ayuda!! Me sale este error al intentar enviar mensajes desde mi correo electronico de Zoho! Tampoco recibo correos pues cuando me envia rebotan. Ayuda, Me urge enviar unos correo importantes!! Quedo atenta MAGDA HERNANDEZ +5731120888408
                                                                                                            • Is there a way to automatically add Secondary Contacts (CCs) when creating a new ticket for specific customers?

                                                                                                              Some of our customers want multiple contacts to receive all notifications from our support team. Is there a way to automatically add secondary contacts to a ticket when our support team opens a new ticket and associates it with an account? This would
                                                                                                            • How to Set Up Zoho Mail Without Cloudflare on My Website

                                                                                                              I'm having some trouble with Cloudflare here in Pakistan. I want to configure Zoho Mail for my domain, but I'm not sure how to set it up without going through Cloudflare. My website, https://getcrunchyrollapk.com/ , is currently using CF, but I'd like
                                                                                                            • Spam is Being Forwarded

                                                                                                              I am filtering a certain sender directly to the Trash folder. Those messages are still being forwarded. Is this supposed to happen?
                                                                                                            • IMAP Block

                                                                                                              My two accounts have been blocked and I am not able to unblocked them myself. Please respond to email, I am traveling and this is urgent.
                                                                                                            • "DKIM not configured"

                                                                                                              Hello. I have been attempting get the DKIM verified but Toolkit keeps sending the message that it is not configured, but both Namecheap and Zoho show it as configured properly. What am I missing?
                                                                                                            • Zoho mail with custom domain not receiving email

                                                                                                              i registered zoho mail with my own domain. I can login and access the mail app. I tried to send email from an outlook email account and an icloud email account. Both emails were not received. My plan is free. I also tried to send email from this zoho
                                                                                                            • Set connection link name from variable in invokeurl

                                                                                                              Hi, guys. How to set in parameter "connection" a variable, instead of a string. connectionLinkName = manager.get('connectionLinkName').toString(); response = invokeurl [ url :"https://www.googleapis.com/calendar/v3/freeBusy" type :POST parameters:requestParams.toString()
                                                                                                            • New Mandatory One-Click Unsubscribe Link Overshadowing Custom Unsubscribe Link

                                                                                                              I was recently informed by Zoho CRM Support that they are now mandated by the large email service providers like Google and Yahoo to provide a one-click unsubscribe option in the header (not the body) of all mass emails. I have a custom unsubscribe link
                                                                                                            • Waterfall Chart

                                                                                                              Hello, I would like to create a waterfall chart on Zoho analytics which shows the movement in changes of budget throughout a few months, on a weekly basis. Should look something like the picture below. Does anyone know how to?
                                                                                                            • Help Center and SEO: Any Benefit to My Domain-Mapped Website Ranking?

                                                                                                              First of, I love the Help Center which I've just decided to integrate into my website to replace its old-fashioned FAQs. So much more to achieve there now! Lots of new benefits to the site visitors and to me in terms of organizing and delivering all the
                                                                                                            • Issue with Importing Notes against Leads

                                                                                                              Hi, I am attempting to import some Notes into Zoho CRM which need to be assigned to various Leads. I have created a csv file which I am testing that contains just one record. This csv file contains the following columns: Note Id Parent Id       (I have
                                                                                                            • Trigger a Workflow Function if an Attachment (Related List) has been added

                                                                                                              Hello, I have a Case Module with a related list which is Attachment. I want to trigger a workflow if I added an attachment. I've seen some topics about this in zoho community that was posted few months ago and based on the answers, there is no trigger
                                                                                                            • Option to Hide Project Overview for Client Profiles

                                                                                                              In Zoho Projects, the Project Overview section is currently visible to client profiles by default. While user profiles already have the option to restrict or hide access to the project overview, the same flexibility isn’t available for client profiles.
                                                                                                            • Creator Add Records through API - Workflows not triggered ?

                                                                                                              Hi Everyone, I am trying to add records to my Creator application through a third party app that I am developing. Currently, I am testing this through Postman. The records I need to add have a lot of workflows to run to populate dropdowns, fields, use
                                                                                                            • Zoho Books Idea - Include another field in Bank Details for Address

                                                                                                              Hi Books team, Currently use the Description field in the Bank Details to store the bank's address. This works fine but it would be great if you could add another field for Bank Address, so that other notes about the bank account could be stored in the
                                                                                                            • Zoho Books Idea - Bank Details Button on Banking

                                                                                                              Hi Books team, Sometimes I'm asked to share bank details with a customer or a colleague. So I go to the Banking Module, find the correct bank account, click Setting > Edit, then copy and paste the bank details. Wouldn't it be great if there was a button
                                                                                                            • Zoho Error: This Operation has been restricted. Please contact support-as@zohocorp.com for further details

                                                                                                              Hello There, l tried to verify my domain (florindagoreti.com.br) and its shows this error: This Operation has been restricted. Please contact support-as@zohocorp.com for further details. Screenshot Given Below -  please check what went wrong. Thanks
                                                                                                            • Zoho Books | Product updates | August 2025

                                                                                                              Hello users, We’ve rolled out new features and enhancements in Zoho Books. From the right sidebar where you can manage all your widgets, to integrating Zoho Payments feeds in Zoho Books, explore the updates designed to enhance your bookkeeping experience.
                                                                                                            • Important Update: Changes to Google Translate Support in Zoho SalesIQ

                                                                                                              We’re updating our default chat translation options across all Zoho SalesIQ data centres to offer a more secure, in-house solution for your translation needs. What’s changing? We will be offering Zoho Translate (our in-house tool) as the default translation
                                                                                                            • FSM Improvement Idea - Show an Import button when there is no data

                                                                                                              I am setting up FSM for a client and I noticed that there is no option to import data, see screenshot below. Even when you click Create Contact there is only an option to Import from Zoho Invoice. It is only after you add at lease 1 record that the Import
                                                                                                            • Zoho CRM Community Digest - July P1 | 2025

                                                                                                              Hey everyone, The start of July 2025 marked a special milestone: 200 posts in our Kaizen series! For those new here, Kaizen is a go-to series for Zoho CRM developers, where we regularly share best practices, tips, and expert insights to help you build
                                                                                                            • Elevate your CX delivery using CommandCenter 2.0: Simplified builder; seamless orchestration

                                                                                                              Most businesses want to create memorable customer experiences—but they often find it hard to keep them smooth, especially as they grow. To achieve a state of flow across their processes, teams often stitch together a series of automations using Workflow
                                                                                                            • can't login Kiosk URGENT

                                                                                                              already try, can't login pls help to support. thanks.
                                                                                                            • Join our BI & Analytics Workshop at Zoholics UK 🇬🇧

                                                                                                              Hello users, We are thrilled to announce a hands-on workshop at Zoholics UK, 2025, led by Ashwinth and Alan, our Product Experts. This session is designed for anyone who wants to move beyond raw data and truly understand their business performance using
                                                                                                            • What’s New in Zoho Expense (April – July 2025)

                                                                                                              Hello users, We're happy to bring you the latest updates and enhancements we've made to Zoho Expense over the past three months, which include introducing the Trip Expense Summary report in Analytics, extending Chatbot support to more editions, rolling
                                                                                                            • 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
                                                                                                            • Next Page