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


      • Recent Topics

      • Zoho Desk iOS and Android app update: Attachment restriction

        Hello, everyone! We are excited to introduce an option to restrict uploading certain attachment types on the Zoho Desk app. This feature allows you to specify the types of attachments are allowed to be uploaded and shared within the Zoho Desk. This can
      • Zoho CRM Outlook integration: no option showing up even after installation

        I followed the instructions on this page to install the add-in: https://help.zoho.com/portal/en/kb/crm/integrations/microsoft/ms-outlook-add-in-for-zoho-crm/articles/outlook-add-in-for-zoho-crm#Understanding_the_add-in But I don't see the options in Outlook
      • Portal URL Not Working?

        When I view my Company Profile, it shows my portal URL as being not created although it has been.  For example my profile shows the following:  https://meeting.zoho.com/a/..  The directory name that I chose is missing and it appears that I need to create a new Portal URL although one already exists for my organization. When I try to visit the URL that I previously created, I receive a "Page Not Found" error.
      • Improve user efficiency with Automated reminders

        When it comes to business, keeping up with the deliverables is imperative. Automated reminders help you just with that, allowing you to set up notifications that are automatically triggered to your workspace users to remind them about important updates,
      • Setup Outlook for domain email address fails

        I am trying to setup outlook for one of my domains email addresses and I am unable to add the account in Outlook I get "Operation could not be completed" errors. I am using the imap.zoho.com 993 for incoming and smtp.zoho.com 465 for outgoing email. I
      • Free webinar alert! Empower Customer Experience in a Changing World with Zoho Desk and Zoho Workplace

        Hello Zoho Workplace Community! We’re back with another exciting webinar—and this time, it’s all about delivering exceptional customer experiences. Join us for "Empower Customer Experience in a Changing World with Zoho Desk and Zoho Workplace," where
      • Date & Time Field | Minimum 24 hour notice.

        I'm trying to use Zoho Forms to build a booking request form. I have the date and time field selected as the field users can select their booking time for. My issue is I need a minimum of 24 hour notice for each appointment. I have it sent to only future
      • Auto-sync field of lookup value

        This feature has been requested many times in the discussion Field of Lookup Announcement and this post aims to track it separately. At the moment the value of a 'field of lookup' is a snapshot but once the parent lookup field is updated the values diverge.
      • Bigin iOS app update - Introducing Card Scanner and initiating WhatsApp conversations using pre-approved templates.

        Hello everyone! In the latest iOS (v1.11.3) version of the Bigin app, we have introduced the following features: Card Scanner Initiating WhatsApp conversations. Card Scanner: Our new Card Scanner feature extracts contact information from business cards.
      • Check out in Meetings

        Why there is no check out in Meetings of Zoho CRM, very difficult to track
      • Connecting Portals from different Zoho apps

        Hi, I note that Zoho has functionality for customer portals for several of the Zoho apps, like CRM, Projects, Desk etc. Is there any way to connect these portals?  It would be great if we could give our customers access to a portal in which they could
      • Automate Note Creation for Service Appointments

        Hi Latha, I hope you're doing great. Thank you for your continued support in helping resolve previous issues — it's truly appreciated. I'm currently working on automating another workflow using Deluge in the Service_Appointment module. Specifically, I
      • Creating Email template that attaches file uploaded in specific field.

        If there's a way to do this using Zoho CRM's built-in features, then this has eluded me! I'm looking to create a workflow that automatically sends an email upon execution, and that email includes an attachment uploaded in a specific field. Email templates
      • Default Lookup Field Value based on Picklist

        How do I change a lookup field value based on another field's value, while creating/editing a record using form? I have a picklist of different types of Loans. For example: PPP, EDIL, Term, etc. When I create a record using the form, if I choose PPP from
      • Portal permission for report only

        Hello, I have a hard time setting portal permission for my users. I have a form that is an order subform for items. I use that subform to create a filtered report for sellers to see their own orders, but at the same time I have to give them access to
      • How to modify query from a DataBridge Connection

        Hello, I just installed the new DataBridge tool to import data to our Zoho Analytycs account from our local database. It works well so far, and data gets sync every day. The only issue that I found is that we do not know how to modify the query that imports
      • Duplicating Forms doesn't duplicate Forms attachment path to workdrive

        Hi, I have this user, who uses one forms and duplicates it when needed and update the content. For him, it's important to have the submission forms saved in a specific folder inside Workdrive (as this PDF is transmitted later to another team). However,
      • Add Lookup Field in Tasks Module

        Hello, I have a need to add a Lookup field in addition to the ones that are already there in the Tasks module. I've seen this thread and so understand that the reason lookup fields may not be part of it is that there are already links to the tables (https://help.zoho.com/portal/en/community/topic/custom-fields-on-task-module).
      • Tip of the Week #55 – Assign roles to inbox members

        Ever heard the phrase, "Right people, right access"? That’s exactly what you can achieve in Zoho TeamInbox by assigning roles to your inbox members! In any team, not everyone needs the same level of access to your shared inboxes. Some members may need
      • iOS 18 is here! Discover the enhanced Bigin app with iOS 18, iPadOS 18 and macOS Sequoia.

        Hello, everyone! We are excited to be back with new features and enhancements for the Bigin app. Let us take a look at the new iOS 18 and iPadOS 18 features. The following is the list of features covered in this update: Control widgets. New app icons.
      • Basic Lookup Field Update Function

        Hi! So I have no idea what I'm doing in Deluge but I need to get a custom function to run On Create or Edit that sets the value of a Lookup Field based on the contents of another field. Seems simple enough, but I have looked through dozens of other similar
      • Fourth Insight - The power of Multi-Layouts

        The Wheels of Ticketing - Desk Stories The power of Multi-Layouts In the previous insights, we have established that layouts are the foundation for a ticketing system, and fields are the building blocks for the same system. Fundamentals of layouts Fields
      • Filter Multi-Line Properties with Plain Large Text

        To be able to filter fields that feature Plain large text, I am only able to filter on plain small text when you offer 3 separate options.
      • One notebook is on my Android phone app, but not on Web or PC app.

        This problem started in stages. At first my phone was occasionally failing to sync. Then I noticed two things added to my Phone App. One was an existing notebook had a new cover, and the other was a new Note Card with an odd text in it. These were only
      • App Crash on MacBook Pro

        Hi Zoho, I am still struggling to keep Zoho Notebook stable on my Mac platform. I have sent in a couple of crash logs and I am making sure I have the latest version from the Mac App store. I love this application and really want to get it stable. The
      • Share saved filters between others

        Hi, I am in charge to setup all zoho system in our company. I am preparing saved filters for everybody, but the only one can see its me. How can others see it? Thanks
      • Possible to reorder Pipelines position?

        I have multiple Pipelines and want to reorder their positions, so that in the Deals module record for the Pipeline field, I have them ordered in a certain way. Is there a way to reorder the position of the Pipelines without deleting existing Pipelines
      • Unable to invite contacts

        Hi! I'm unable to invite contacts as end-users from my trial account. The green pop-up displays "Invited succesfully" but the email never arrives, nor the re-invitation - even though it's "sucessfully" as well. Tried with several e-mail accounts, even
      • ZOHO BOOKS - RECEIVING MORE ITEMS THAN ORDERED

        Hello, When trying to enter a vendor's bill that contains items with bigger quantity than ordered in the PO (it happens quite often) - The system would not let us save the bill and show this error: "Quantity recorded cannot be more than quantity ordered." 
      • Automating Sales Order Confirmation & Picklist Generation in Zoho Inventory

        Hi everyone, I’m looking to automate the sales order creation and confirmation process in Zoho Inventory, along with the automatic generation of picklists with bin-level details. Here’s what I need: Sales orders should be automatically created and confirmed
      • Parent-Child Tickets using API or Deluge

        Hi Everyone, We are looking at the parent-child ticketing features in Zoho Desk. We want to be able to create a parent ticket at customer level and nest child tickets underneath. The issue we are facing is to be able to automate this. I'm checking the
      • Spotlight series #7: Path animation

        Animating objects on your slide helps make your presentations lively and interesting. Animations add movement to an otherwise static deck, which helps grab your audience's attention. While you can animate your objects' entry and exit, or use animation
      • Generate Unique Customer ID for Each for All Contacts

        Generate Unique Customer ID for Each for All Contacts
      • Zoho Thrive is getting a revamp: Here’s what’s changing

        We’re excited to bring you an upgraded Zoho Thrive experience! This update features a more intuitive interface, improved navigation, and enhancements to help you manage your affiliate and loyalty programs with ease. What’s new? A more flexible start:
      • Does Zoho Learn integrate with Zoho Connect,People,Workdrive,Project,Desk?

        Can we propose Zoho LEarn as a centralised Knowledge Portal tool that can get synched with the other Zoho products and serve as a central Knowledge repository?
      • Zoho Forms to Zoho Projects

        Can Zoho Forms be used to collect task details and automatically create a new task under a specific project in Zoho Projects upon submission?
      • Quick resend/One-off send function

        Sometimes I might follow up with someone that opened an email and they say "Can you please send the email to me again?" Also, on occasion, a new person may have joined my mailing list and just missed a recent campaign, so it would be VERY handy just to send them the campaign email. Obviously, there is currently no quick or easy way to do this. So, would it be possible to have such a feature? It could work from a number of places, but probably the quickest and easiest way to implement it is under
      • Cliq iOS can't see shared screen

        Hello, I had this morning a video call with a colleague. She is using Cliq Desktop MacOS and wanted to share her screen with me. I'm on iPad. I noticed, while she shared her screen, I could only see her video, but not the shared screen... Does Cliq iOS is able to display shared screen, or is it somewhere else to be found ? Regards
      • Workdrive - copy permissions

        I am trying to customize sub folder, which I understand fully from below https://help.zoho.com/portal/en/kb/workdrive/team-folders/manage/articles/customize-folder-permissions-in-a-team-folder#Customize_permissions_during_folder_creation However I want
      • campaings flagging domain error but crm says OK

        campaings flags error with domain buy crm says notig wrong - this is new, help
      • Next Page