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

                                                                                                            • Quickbooks invoice with Zoho Creator

                                                                                                              Is it possible to push data from Zoho Creator directly to an invoice on QuickBooks? If so, where can I find information on how to do this?
                                                                                                            • Help: Capture full page URL in hidden field when same Zoho Form is embedded on multiple pages (iframe)

                                                                                                              Hi all, Goal Use one Zoho Form across multiple pages and record the exact page URL (incl. subdomain + path + hash) where the user submitted it. Example pages: https://www.example.com/cargo/ https://www.example.com/cargo/containers/#contact https://cargo.example.com/auto/
                                                                                                            • Automatically Populate fields - HELP!

                                                                                                              There have been many discussions on this but I still can't seem to get it to work for me. I am trying to create a lookup field and have other fields automatically populate. Based on the instructions in the Help Center, I should be using the "on user input". It's just not working, here is the layout...   Both forms are in the same application. Current form is called Add Note, form to fetch records from is called Add Client. Lookup field is called Select_Client_ID related field in fetch form is called
                                                                                                            • Push notifications to portal users

                                                                                                              Hi all, it is possible to send push notifications to portal users?
                                                                                                            • Rename the attachment from record template pdf in the sendmail deluge script

                                                                                                              Hello Zoho, I urgently need a feature to rename record templates that I send via the sendmail feature. The program I created sends emails to clients with an invoices that have been created in the invoice database. If the user selects 3 invoice numbers,
                                                                                                            • Alt Text On Multiple Images

                                                                                                              I'm using Zoho Social to post to a charity website. Often the posts have multiple images, but it seems there is only one field for Alt Text. Does that mean I can only include it for the first image? Or is there a way to add alt text for all the imag
                                                                                                            • [SOLVED] Getting 401 when trying to download ticket attachment via API

                                                                                                              I'm able to use the API just fine to access ticket content. But I cannot download ticket attachment, keep getting 401 Client Error. Example: https://desk.zoho.com.au/api/v1/tickets/{ticket_id}/attachments/{attachment_id}/content?orgId={org_id} For headers,
                                                                                                            • Zoho project – Workdrive integration.

                                                                                                              Hello everyone, I was wondering something, we did the Zoho projects integration with Zoho Workdrive but nowhere during this integration we could set the location of the folders that would be automatically created in Workdrive. As I understand it, it creates
                                                                                                            • Scriptを埋め込みたくてOn User Inputを探しているのですが・・・

                                                                                                              編集モードで、Scriptを埋め込みたい項目を選択し、「項目のプロパティ」パネルで、その下のほうに「フィールドアクション(Field Actions)」という見出しがあると聞いたのですが、そもそも、それが見つかりません。そのために、On User Inputなどのイベントが選べません。 画面の英語を日本語に訳しているためにわけわからん状態になっているのかも知れませんが、わかる方、いらっしゃいますか?
                                                                                                            • Problem with cloud query exceeded

                                                                                                              When making a call I get this error, It is associated with a function in node that calls external APIs This is the code //tokenConsultar = thisapp.ObtenerToken(); //input.token = tokenConsultar.get("output").toMap().get("token");
                                                                                                            • Showing Total of Funnel Chart Legend (With Values) Items

                                                                                                              Hi, We are using the funnel type chart for displaying our zCRM sales pipeline stages and associated sum of deals in each stage.  We have configured the legend to show the associated value (Deal Amount (Sum)) for each stage adjacent to the legend items (Stages). Is there a way to display the total of the values in the same chart?  For example, at the bottom of the legend or maybe as a #merge placeholder in the legend title?
                                                                                                            • How to Convert VCF Contacts to CSV using Excel

                                                                                                              Many users switch from traditional address books to digital formats like vCard and CSV. These formats allow users to easily manage their contacts. However, a difficulty comes when you need to transfer your contact information to another application or
                                                                                                            • Field authorization for Linking module in Zoho CRM portal

                                                                                                              Hi guys! Currently building a customer portal for one of my clients, and I ran into a bit of a roadblock while using a multi-select lookup field. The issue is that there is no way to hide or define access in the linking module created by this multi-select
                                                                                                            • Kaizen #63 - Layout Rules in Zoho CRM

                                                                                                              Hello and welcome to another week of Kaizen! This week, we will be discussing Layout Rules in Zoho CRM. If you need to modify the layout of a module based on user inputs, or to show or hide sections based on the value of a specific field, we have got
                                                                                                            • Zoho CRM Portals - allow access per account

                                                                                                              Hello all, I am trying to set up a portal for our customer but I seem to be hitting an obstacle and I am not sure if it is my problem or a limitation in the software. So basically the way I understand the portal Contact Email > Each Record or Related
                                                                                                            • Android - Writer não acentua em Português com teclado bluetooth

                                                                                                              Gosto muito do Zoho, tanto o Note quando o Writer. Infelizmente, o Writer sofre de um problema sério: ao usar um teclado bluetooth, forma mais cômoda de lidar com um processador de texto, os acentos (todos!) da Língua Portuguesa não são aceitos. Todos
                                                                                                            • Set File Upload fields as mandatory

                                                                                                              Currently the CRM for some reason lacks the ability to set a file upload field as mandatory So we have an issue We have a requirement that before a Deal stage is set as Deal is Won the member needs to upload a file Now for some weird reason in Zoho I
                                                                                                            • Editing HTML in Zoho CRM Email Template

                                                                                                              I am trying to create a template within the CRM email option, but need to be able to use custom HTML. There does not seem to be a way to do so.
                                                                                                            • Ability to CC on a mass email

                                                                                                              Ability to CC someone on a mass email.
                                                                                                            • How to make attachments mandatory

                                                                                                              I want the user to be unable to mark an opportunity as Closed – Won if it doesn’t have any attachments. I’ve already tried client scripts and functions, but nothing worked.
                                                                                                            • SLA ticket report

                                                                                                              From data to decisions: A deep dive into ticketing system reports Service level agreement (SLA) ticket reports in a help desk system are crucial for ensuring that services are delivered according to established commitments. They help maintain accountability
                                                                                                            • Zoho Backstage - PCI Compliance / Web Security

                                                                                                              I have a couple of questions related to Backstage and payment processing.... 1. my purchasing division is not giving approval to use Backstage yet because of some security issues. In order for us to take payments via a payment gateway like Authorize.net
                                                                                                            • Zoho Tables August 2025 Update: Faster and Smoother

                                                                                                              We’ve been working behind the scenes to make Zoho Tables faster, lighter, and more reliable. Here are the highlights: Faster Response Times Optimised the way responses are generated. Reduced memory consumption by 20–25%, leading to smoother performance
                                                                                                            • Video Upload from app says "unsupported aspect ratio" but is verified to be correct.

                                                                                                              I and my social media person are experiencing a problem where Social will not accept video uploads to Instagram. The error we receive is "unsupported aspect ratio" but looking directly at the file in question we see that the width and ratio both match
                                                                                                            • Zoho sheet - Zoho expense

                                                                                                              I want to schedule to create an expense using Zoho Sheet and flow. That is the EMI that I pay on a particular date to the bank and should be itemised, like principal and interest on the loan. Can someone help me in this regard??
                                                                                                            • Ability to configure a schedule/shift for each user and/or crew in Zoho FSM

                                                                                                              Hello, In our team of Field Agents, we have different shifts. Some field agent always work from 7:00 AM to 4:00 PM while others work the evening shift like 4:00 PM to 11:00 PM. Sometime shift are on weekdays only or on weekend. It would be great to be
                                                                                                            • Free webinar: Streamlining customer service paperwork with the Zoho Sign extension for Zoho Desk

                                                                                                              Hello Everyone! Have you been wondering about bridging the gap between digitised customer service and business paperwork? Join our free webinar to learn how you can do this by connecting Zoho Sign, our digital signature app, with Zoho Desk, our online
                                                                                                            • Zoho Books | Product updates | July 2025

                                                                                                              Hello users, We’ve rolled out new features and enhancements in Zoho Books. From plan-based trials to the option to mark PDF templates as inactive, explore the updates designed to enhance your bookkeeping experience. Introducing Plan Based Trials in Zoho
                                                                                                            • Mail Search should allow grouping by conversation like Gmail.

                                                                                                              Having switched from gmail I have found the search function hard to use. Mostly because mail is not grouped by conversation in search. If I search for a word when looking for a conversation had with someone then sometimes 10 emails will come up from the
                                                                                                            • Improve Zoho Learn updated article notifications

                                                                                                              I noticed today while updating an article, that the notification users get says "[User Name] has published article [Article Name]..." My feedback to the product team is that it would be really helpful for an end user, if the system notification differentiated
                                                                                                            • Safari Support

                                                                                                              Safari, the world's second largest browser, zoho desk does not officially or fully support. That needs to change.
                                                                                                            • Can I get images from an "Image Upload" field in a webhook?

                                                                                                              I want to send images from 2 "image upload" fields via a webhook. Is this possible?
                                                                                                            • Ticket closure notification - all contacts cc'd on email thread

                                                                                                              Hello, If a client sends an email to our service desk and cc's in other people that work at the same company - so that they are in the loop of the service request. When the we close the ticket, only the ticket owner (person who emailed us - which created
                                                                                                            • Inactive account cleanup policy for Zoho Sign

                                                                                                              Zoho Sign reserves the right to delete accounts that are license free and inactive for more than 120 days. The account deletion will be initiated only after the user receives prior email notice about possible data deletion and how to backup the data.
                                                                                                            • Missde API documentation for Sales Receipt

                                                                                                              Hi! I noticed that the Sales Receipt endpoint is not currently listed in your API documentation (https://www.zoho.com/books/api/v3/introduction/). Could you please provide any available temporary documentation for this endpoint, along with a detailed
                                                                                                            • Multi-currency in Zoho CRM Forecast and Reports

                                                                                                              As a company we have branches in 4 different countries with as many different currencies. Our Sales Teams would like to work with their local currency as much as possible. The Forecast module using only 1 currency is practically usable only by the sales
                                                                                                            • How to select from pricebook when creating a salesorder or quote

                                                                                                              I am creating a sales order and when selecting the Products I do not see any where to select from pricebooks. How do i associate this to my orders?
                                                                                                            • Proposal for Creating a Unique "Address" Entity in Zoho FSM

                                                                                                              The "Address" entity is one of the most critical components for a service-oriented company. While homeowners may change and servicing companies may vary, the address itself remains constant. This constancy is essential for subsequent services, as it provides
                                                                                                            • Automatic Matching from Bank Statements / Feeds

                                                                                                              Is it possible to have transactions from a feed or bank statement automatically match when certain criteria are met? My use case, which is pretty broadly applicable, is e-commerce transactions for merchant services accounts (clearing accounts). In these
                                                                                                            • I cannot find my older documents from 2024 and 2023

                                                                                                              I cannot find my older documents from 2024 and 2023.
                                                                                                            • Next Page