Restrictions and validations in subforms using Client Script

Restrictions and validations in subforms using Client Script



Hello everyone!

Welcome back to another exciting Kaizen post on Client Script! 

In this edition, we’re taking a closer look at Client Script Support for Subforms with the help of the following scenario.

" Zylker, a manufacturing company, uses the "Orders" module to place Orders . They fill in a subform called "Product List". Now, the Admin wants to enforce the following restrictions on this subform in detail page:
  • Disable row deletion
  • Prevent cloning and adding rows
  • Make the "Unit Price" field read-only for salespersons "

In this post,

  1. What are Subform event
  2. Possible actions in Subform using Client Script
  3. Use Case
  4. Disable row deletion within the subform
  5. Prevent cloning and addition of rows in subform
  6. Make the "Unit Price" field read-only for salespersons
  7. Summary
  8. Related Links


1.What are Subform Events

Subform events are triggered by user actions, such as adding or deleting rows or updating data in subform. These events allow you to run Client scripts for validation, automation, or dynamic updates. Here is the list of subform events.
  • onCellChange – Triggered when a cell value is changed and the keyboard or mouse focus moves out of the subform cell.
  • onRowAdd – Fires immediately after a new row is added in a subform.
  • onRowDelete – Executes right after a row is deleted from a subform.
  • beforeRowDelete – Invoked before a subform row is deleted; can be used to prevent deletion.
  • beforeRowUpdate – Triggered before a subform row is updated on Detail pages; useful for validations or preventing changes.
Click here to know more about Subform Events.
These events are supported in the following Pages of Zoho CRM
  • Standard - Create/Edit/Clone Pages, Detail page
  • Canvas - Create/Edit/Clone Pages, Detail page
  • Wizard - Create/Edit Pages
2. Possible actions in Subform using Client Script




Click here to view the detailed documentation about the Client Script ZDKs related to Subform.

Notes
 Note :

The setValue() method for a subform row and cell on the Detail Pages will only work when the row is in edit mode.

3. Solution

To accomplish the solution for the use case (stated at the beginning of the post), you need to create the following Client Scripts in detail Page.

3.A. Disable row deletion within the subform

  • Go to Setup > Developer Space > Client Script. Click +New Script.
  • Specify the details to create a script. 
  • Click Next.


Script :

  1. ZDK.Client.showAlert("Deleting rows is not allowed here");
  2. return false
  • This script blocks row deletion and shows an alert message.

  • Here is the syntax of showAlert().


  • You can see that the Client Script Triggers an alert message and prevents the deletion of rows.



3.B. Disable adding and cloning of rows in subform
  • Go to Setup > Developer Space > Client Script. Click +New Script.
  • Specify the details to create a script. 
  • Click Next.


Script: 

  1. ZDK.Client.showAlert("Adding and cloning rows is not allowed in this subform")
  2. return false;
  • You can see that the Client Script Triggers an alert message and prevents the addition of a new row. 



3.C. Make the "Unit Price" field read-only for salespersons

  • Go to Setup > Developer Space > Client Script. Click +New Script.
  • Specify the details to create a script. 
  • Click Next.

Script:
  1.   var user = ZDK.Apps.CRM.Users.fetchById($Crm.user.id);
  2. if (user.profile.name == 'Salesperson') {
  3.     var field_obj = ZDK.Page.getSubform("Product_list").getField('Unit_Price');
  4.     field_obj.setReadOnly(true);
  5. }

  • Here, 
  • $Crm refers to the Client Script Constant.





  • Click here to know more about other ZDKs and functions related to Client Script.
  • Here is how Client Script works.




Summary

1. What are the events available for subforms
2. What are the supported actions in subforms
3. How to make a field read only in a subform for a particular profile
4. How to prevent adding rows to a subform.

Related Links

Idea
Previous Post: Kaizen 185 - Subqueries in COQL AP |  Kaizen Collection: Home


    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

                                                                                                            • Can i connect 2 instagram accounts to 1 brand?

                                                                                                              Can i connect 2 instagram accounts to 1 brand? Or Do i need to create 2 brands for that? also under what subscription package will this apply?
                                                                                                            • Workdrive on Android - Gallery Photo Backups

                                                                                                              Hello, Is there any way of backing up the photos on my android phone directly to a specific folder on Workdrive? Assuming i have the workdrive app installed on the phone in question. Emma
                                                                                                            • Integración Books para cumplir la ley Crea y Crece y Ley Antifraude (VeriFactu)

                                                                                                              Hola: En principio, en julio de 2025, entra en vigor la ley Crea y Crece y Ley Antifraude (VeriFactu). ¿Sabéis si Zoho va a cumplir con la ley para cumplir con la facturación electrónica conectada a Hacienda? Gracias
                                                                                                            • YouTube Live #1: AI-powered agreement management with Zia and Zoho Sign

                                                                                                              Hi there! We're excited to announce Zoho Sign’s first YouTube live series, where you can catch the latest updates and interact with our Zoho Sign experts, pose questions, and discover lesser-known features. We're starting off by riding the AI wave in
                                                                                                            • Mass Mail Statistics - Number of unsent emails

                                                                                                              How do I find out which emails were not sent?
                                                                                                            • How to add a % Growth column for year-over-year comparison (2024 vs 2025)

                                                                                                              Hello, I am trying to build a monthly revenue comparison between 2024 and 2025 in Zoho CRM Analytics. My current setup is: Module: Deals (Affaires) Filter: Stage = Closed Won Date field: Closing Date Grouping: By Month Metrics: Sum of Amount for 2024,
                                                                                                            • How to searchByCriteria records that are under approval?

                                                                                                              I need to search for both approved and pending approval records Is that possible with this method? Or I need to a different method? var priceReqID = $Page.record_id; log(priceReqID); var records = ZDK.Apps.CRM.Price_List_Item.searchByCriteria("Price_Request:equals:"
                                                                                                            • Power of Automation::Streamline log hours to work hours upon task completion.

                                                                                                              Hello Everyone, A Custom Function is a user-written set of code to achieve a specific requirement. Set the required conditions needed as to when to trigger using the Workflow rules (be it Tasks / Project) and associate the custom function to it. Requirement:-
                                                                                                            • How to add Simple Analytics to Zoho Pages?

                                                                                                              I have a website with Zoho Pages, how do I add Simple Analytics on it? They seem to have code they need to be embedded https://docs.simpleanalytics.com/script
                                                                                                            • Product details removed during update from other system

                                                                                                              We maintain our product details in an other system. These details are synchronized with Zoho at the end of each day, through an API. This has worked perfectly sofar. But last Monday, all product codes and some other product data have been wiped during
                                                                                                            • End Date in Zoho Bookings

                                                                                                              When I give my appointments a 30 minutes time I would expect the software not to even show the End Time.  But it actually makes the user pick an End Time.  Did I just miss a setting?  
                                                                                                            • I hate the new user UI with the bar on the left

                                                                                                              How can I reverse this?
                                                                                                            • Cant seem to delete an email account

                                                                                                              Hello, I have researching for 4 days how to delete an email account and I am absolutely without a clue. The email account I am trying to delete is support<AT>fyshoes<dot>com. It's the first email account I made and it (is???) was associated with the super user (me). I have since changed it to adming<AT>fychoes<dot>com and I see the support email in my list but I just cant seem to get rid of it. Ultimately I want to associate that email account with another user that I want to add. This is really
                                                                                                            • Commerce Order as Invoice instead of Sales Order?

                                                                                                              I need a purchase made on my Commerce Site to result in an Invoice for services instead of a Sales Order that will be pushed to Books. My customers don't pay until I after I add some details to their transaction. Can I change the settings to make this
                                                                                                            • Sync desktop folders instantly with WorkDrive TrueSync (Beta)

                                                                                                              Keeping your important files backed up and accessible has never been easier! With WorkDrive desktop app (TrueSync), you can now automatically sync specific desktop folders to WorkDrive Web, ensuring seamless, real-time updates across devices. Important:
                                                                                                            • Script that deletes a record?

                                                                                                              We're using WP Plugin "Integration for WooCommerce and Zoho Pro", and have created a couple of Feeds to send data to Zoho. We are trying to create Contact records, but only based upon condition. Tried to make it with small Deluge function and Workflow,
                                                                                                            • Introducing Profile Summary: Faster Candidate Insights with Zia

                                                                                                              We’re excited to launch Profile Summary, a powerful new feature in Zoho Recruit that transforms how you review candidate profiles. What used to take minutes of resume scanning can now be assessed in seconds—thanks to Zia. A Quick Example Say you’re hiring
                                                                                                            • Import data into Multi-Select lookup field from CSV/Excel

                                                                                                              How to import data into a multi-select lookup field from the CSV/Excel Sheet? Let's say I have an Accounts multi-select lookup field in the Deals module and I want to import the Deals with Accounts field. Steps:- 1. Create/edit a multi-select lookup field
                                                                                                            • Auto Capitalize First Letter of Words

                                                                                                              Hi I am completely new to ZOHO and am trying to build a database. How can i make it when a address is entered into a form field like this: main st it automatically changes is to show: Main St Thank You
                                                                                                            • A formula that capitalises the first letter of each word

                                                                                                              Hi all, is there a zoho formula that can capitalise the first letter of each word in a string? INITCAP only capitalises the first letter of the first word.
                                                                                                            • Add Analytics function for Title case (capitalising each word in a string)

                                                                                                              At present, you can only capitalise each word in a string in Analytics during data import. It would be really useful to be able to do this with a formula column, but there is no Title Case function.
                                                                                                            • Office 365 and CRM mail integration: permission required

                                                                                                              Has anyone run into this weird problem? My email server is Office 365. When I try to configure Zoho CRM to use this server, a Microsoft popup window opens requesting user and password. After entering that, I get a message in the Microsoft window saying
                                                                                                            • Updating Subform Record from other Form

                                                                                                              Just wanted to ask how to properly approach this. I have 2 forms and would like to trigger an auto update on the subform once record submitted. block below only updates 1 row for each recordRow in input.AV_System { AssetRecord = Site_Asset_Services[SOR_No
                                                                                                            • How to conditionally embed an own internal widget with parameters in an html snippet?

                                                                                                              Hello everyone, I'm trying to create a dynamic view in a page using an HTML snippet. The goal is to display different content based on a URL parameter (input.step). I have successfully managed to conditionally display different forms using the following
                                                                                                            • Reverse payment on accidentally closed invoice.

                                                                                                              An invoice was closed accidentally with the full payment added. However, only partial payment was paid. How can I reopen the invoice and reverse this to update it to show partial payment?
                                                                                                            • Quotes in Commerce?

                                                                                                              In Zoho Ecommerce, I need to be able to generate quotes, negotiate with customers, and then generate invoices. Currently, I plan to integrate Zoho CRM to generate quotes. After negotiation and confirmation, I will push the details to Zoho Ecommerce to
                                                                                                            • Zoho Commerce - Mobile Application

                                                                                                              Does Zoho Commerce have a mobile application for customers to place an order?
                                                                                                            • Adding Markdown text using Zoho Desk API into the Knowledge Base

                                                                                                              Hi Zoho Community members, We currently maintain the documentation of out company in its website. This documentation is written in markdown text format and we would like to add it in Zoho Knowledge Base. Do you know if there is REST API functionality
                                                                                                            • Register user through Phone Number by Generating OTP

                                                                                                              In zoho commerce , I am developing website on online food store Inilialy the user get verification code to their email for registering there account for login. But I need to login using phone number by generating OTP automatically rather than verification
                                                                                                            • Custom Buttons for Mass Actions

                                                                                                              Hello everyone, We’ve just made Custom Buttons in Zoho Recruit even more powerful! You can now create Bulk Action Buttons that let you perform actions on multiple records at once, directly from the List View. What’s new? Until now, custom buttons were
                                                                                                            • Super Admin Access to All Courses and Spaces in Zoho Learn

                                                                                                              Dear Zoho Learn Team, We hope this message finds you well. We are using Zoho Learn extensively for internal and agent training. While managing our courses and spaces, we encountered a significant limitation regarding admin access and course management.
                                                                                                            • Zoho Vault Passwords

                                                                                                              Is there a way to consume Zoho Vault Manager passwords using the API? Thanks in advance.
                                                                                                            • Is the ChatGPT Assistant integration capable of recognizing WhatsApp voice messages?

                                                                                                              I was wondering: if a visitor sends me a voice message on WhatsApp, would the assistant be able to transcribe it and reply to them?
                                                                                                            • Zoho Creator to Zoho CRM Images

                                                                                                              Right now, I am trying to setup a Notes form within Zoho Creator. This Notes will note the Note section under Accounts > Selected Account. Right now, I use Zoho Flow to push the notes and it works just fine, with text only. Images do not get sent (there
                                                                                                            • 【Zoho CRM】レポート機能のアップデート

                                                                                                              ユーザーの皆さま、こんにちは。コミュニティチームの藤澤です。 今回は「Zoho CRM アップデート情報」の中から、レポート機能のアップデートをご紹介します。 目次 1. レポートのエクスポート時のレコードIDの表示について 2. 通貨項目の表示について 3. レポートの削除の監査ログへの反映について 1. レポートのエクスポート時のレコードIDの表示について これまで、レポートをエクスポートするとファイルにレコードIDが必ず含まれていました。レコードIDが識別子として役立つ場合もありますが、実際には多くの企業で参照されることはありません。
                                                                                                            • Translation in zoho bookings

                                                                                                              We cant translate zoho booking emails. The general text we can change. But what about text like: ""Here a link to join the meeting online:"" and "Add to Zoho Calendar" and "Add to Google Calendar"? No professional business have mixed languages. Its looking
                                                                                                            • Help Center IFrame Issue

                                                                                                              I have had a working Help Center on my website using an iframe for a while. But now for some reason the sign in page gets a refused to connect error. Can someone please help. If I go to the url manually it works correclty
                                                                                                            • Is there any way to bill one client in different currencies on different invoices?

                                                                                                              I have some customers who have their currency set as USD and most of their billing is done in USD.   However, from time to time I have a need to bill them in my base currency GBP for some specific invoices, but there seems to be no way of doing this that I can see. The only workaround that I can see is to create two client records for the same client, one for USD billing and one for GBP billing, but this is not an ideal situation. Is it likely that the (hopefully!) soon to arrive multi-currency support
                                                                                                            • API name for all fields in Zoho Project (Standard or custom)

                                                                                                              Hi! I struggle to find easily all API name of all field in Zoho Project to build my API rest with other services. We can find them very fast in CRM but not in PRoject.   Could you share a function to get the list of all API Name of any field of an App
                                                                                                            • 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
                                                                                                            • Next Page