Set default values based on Page Layouts using Client Script

Set default values based on Page Layouts using Client Script

Hello everyone!
Welcome back to another interesting Kaizen post.
In this post, let us discuss how to set default values for fields based on different layouts using Client Script.

In this Kaizen post,
  1. What are Page Layouts?
  2. Client Script is specific for each layout
  3. Use Case
  4. Solution
  5. Summary
  6. Related Links

1. What are Page Layouts?

Page layouts in Zoho CRM enables you to manage the organization and display of fields, sections, and associated details on a record's page. These page layouts are instrumental in personalizing the user interface and optimizing the data entry process to align with your organization's unique requirements. You can assign layouts to user profiles based on your business requirements.

2. Client Script is specific for each layout
Whenever you create a Client Script, you should  mention the layout for which the Client Script should work. So whenever you want to perform actions specific to a particular layout, you can easily accomplish it using Client Script.
In the image below, you can observe that selecting a layout name is a necessary step for configuring a Client Script.


3. Use Case

Consider that Zylker is a manufacturing Company. The customers include both Wholesalers and Retailers. For this purpose, Zylker has two Page Layouts in a custom module named as Orders. One is the Wholesaler-layout and the other is the Retailer-layout. The Wholesaler-layout is assigned to the wholesaler profile and the Retailer-layout is assigned to the retailer profile.

1. Whenever a customer with retailer profile creates an order, the read-only field Account Type should be auto-populated as Retailer.  In the Create page of the Orders module, when the value entered in the field "Number of pieces" is more than 100, then the Payment Method should get populated as Prepaid and should be read-only. 

2. Whenever the customer with wholesaler profile creates an order, the read-only field Account Type should be auto-populated as Wholesaler and the Payment Method should be populated as Prepaid and should be read-only.

4. Solution

For a particular module, the number of Client Scripts to be created differs based on 
The page for which you want the script to work.
The events that should trigger the script.
The layouts for which you want the script to work.

To accomplish this requirement, you need to create three Client Scripts, one for each layout.
  • Client Script for Retailer Layout with onLoad Page event 
  • Client Script for Retailer Layout with onChange Field event 
  • Client Script for Wholesaler Layout with onLoad Page event 

1. Client Script for Retailer Layout with onLoad Page event 

  • 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.

//To populate default value for Account Type
var acc_type = ZDK.Page.getField("Account_Type");
acc_type.setValue("Retailer");
//  To make the field "Account Type" read-only
acc_type.setReadOnly(true);


  • This script gets executed whenever the Retailer - Layout, Create Page of Orders module gets loaded. The getField ZDK fetches the object details about the field Account Type. The value, Retailer can be populated to this field using setvalue(). You can make Account Type field read-only using setReadOnly().
  • Here is how this Client Script works.


2. Client Script for Retailer Layout with onChange Field event 
  • 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.


//To populate  Payment Method when the quantity is more than 100
var no_of_pieces = ZDK.Page.getField("Number_of_pieces");
var payment_method = ZDK.Page.getField("Payment_Method");
if (no_of_pieces.getValue() > 100) {
    payment_method.setValue("Prepaid");
    // To make the field "Payment Method" read-only
    payment_method.setReadOnly(true);
}


  • This script gets executed whenever the user enters a value in the Number of Pieces field in the Retailer - Layout's Create Page of Orders module. The getField ZDK fetches the object details about the fields Number of Pieces and Payment Method. The value, Prepaid will be populated to Payment Method using setvalue(), whenever the value entered in the Number of Pieces is more than 100. You can use getvalue() to get the value entered in a field. You can make this field read-only using setReadOnly().
  • Here is how this Client Script works.



3. Client Script for Wholesaler Layout with onLoad Page event 
  • 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.

//To populate default value for Account Type
var acc_type = ZDK.Page.getField("Account_Type");
acc_type.setValue("Wholesaler");
// To make the fiels "Account Type" read-only
acc_type.setReadOnly(true);
//To populate default value for Payment Method
var payment_method = ZDK.Page.getField("Payment_Method");
payment_method.setValue("Prepaid");
// To make the fiels "Payment Method" read-only
payment_method.setReadOnly(true);


  • This script gets executed whenever the Wholesaler - Layout, Create Page of Orders module gets loaded. The getField ZDK fetches the object details about the fields Account Type and Payment Method. The value, Wholesaler and Prepaid can be populated to the corresponding fields using setvalue(). You can make Payment Method field read-only using setReadOnly().
  • Here is how this Client Script works.

  • Thus using Client Script, you can populate different default values for the same fields located in different page layouts, based on custom conditions.
Note :
Alternatively, you can achieve this using workflow rules. However, if you want instant actions i.e., before updating or saving a record, or if you have exceeded the workflow limit, you can implement this using Client Script.

5. Summary
In this post, we have discussed,
1. Configuring Client Script based on Layout.
2. Choosing the type of Event for a requirement.
3. Using setValue & setReadOnly for the ZDK.Page.getField().

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.

Click here for more details on Client Script in Zoho CRM.

6. Related Links

Please take a look at our Kaizen collection here.

Cheers!


    Access your files securely from anywhere



                        Zoho Developer Community




                                              • Desk Community Learning Series


                                              • Digest


                                              • Functions


                                              • Meetups


                                              • Kbase


                                              • Resources


                                              • Glossary


                                              • Desk Marketplace


                                              • MVP Corner


                                              • Word of the Day


                                              • Ask the Experts





                                                        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

                                                                                                        • Lookup fields can't be used for anything important

                                                                                                          Hi It seems the lookup fields are mostly.... informative, you can at most link stuff between modules... You can't use lookup fields in blueprints, you can't use them in layout rules or anything... It that correct?
                                                                                                        • How do you map a user picklist field to another user picklist field.

                                                                                                          In Zoho Projects, I'm trying to map a custom field (user picklist) in Task Details to a field (user picklist) in the Project Details. How do you get the two to map to each other? This is what I currently have that works for my other fields but doesn't
                                                                                                        • Is it possible to add HTML or a button on email templates in Zoho Desk?

                                                                                                          Hello team, I am working on getting the best use out of Zoho Desk. I have noticed that when you hit 'reply' on a ticket, it comes with a small 'survey' to the recipient saying something like 'how would you rate your experience with us?'... so my question,
                                                                                                        • Is it possible to add buttons on email replies to internal team members?

                                                                                                          Hello everyone, I am currently trying to set up some workflow rules to trigger when a ticket is created. I have noticed there is a button that can be added to email templates when sending email alerts from workflow rules, for example ${Cases.SUPPORT_PORTAL_BUTTON}.
                                                                                                        • Widget function call not working – need help

                                                                                                          Hi everyone, I'm building a widget for Zoho CRM and trying to call a Deluge function from it using ZOHO.CRM.FUNCTIONS.execute, but it's not working. Here’s what I did: I created a Standalone function in Deluge. I'm calling it inside ZOHO.embeddedApp.on("PageLoad",
                                                                                                        • Announcing New Features in Trident for macOS (v.1.19.0)

                                                                                                          Hello everyone! Trident for macOS is here with interesting features and enhancements to elevate your workplace communication. Let's take a quick look at them. View and manage .pst files. A .pst (Personal Storage Table) file is an Outlook Data Storage
                                                                                                        • Introducing the Zoho CRM Lead Magnet plugin for Wordpress

                                                                                                          In this digital era, websites are the most important source of leads. That means your CRM system should be well integrated with your website to contextually capture each and every visitor to turn them into a lead. Introducing the Zoho CRM Lead Magnet plugin for WordPress.  The plugin lets you to: Create webforms using Zoho CRM forms/ Contact form 7 plugin Embed them in your website hosted using Wordpress Automatically capture leads into Zoho CRM with zero attenuation. Not only is the integration
                                                                                                        • Item bulk update

                                                                                                          Why is there no "pruchase rate" to select in the field selection ? We have far more purchase increases than we have selling price amendments !
                                                                                                        • Learning how to customize templates via code and best practices

                                                                                                          Hi! Our developers team want to learn how to edit our template files safely. The last time we messed with these files our site went down for a day and we had to reconfigure it from scratch. What are the best practices to do this? How can we get a template
                                                                                                        • Can't lock timezone in new Zoho Bookings

                                                                                                          Hi, since the new Zoho Bookings has been changed, I cannot seem to lock the timezone in for the meetings. I have set the working hours and location, but when I got on the link, it automatically gives me slots in my timezone. I want to lock it for an in-person
                                                                                                        • How to import subform data - SOLUTION

                                                                                                          To all trying to import subform data, I might have a solution for you. First of all, for this solution to work, the subform data needs to be an independent form (not ad hoc created on the main form). Furthermore, this approach uses Excel sheets - it might not work using CSV/TSV. If this is true, then follow these steps: Import the subform records Then export these records once more including their ID Now prepare an import file for the main form that needs to contain the subform records Within this
                                                                                                        • Can we customize the default client-facing icons?

                                                                                                          Is there any way to customize the client-facing icons that display in the Zoho Bookings UI?  For example, I'm using the Default page theme and would like to modify the default icon that is shown beside "Service."  The icon currently being shown looks like a baseball hat to me (see attached screenshot) which has no relevance to my business or clients. It would be great if Zoho could provide a different, more generic icon (perhaps a bell icon to represent service?) or better yet allow the icons to
                                                                                                        • reCAPTCHA

                                                                                                          Is the Bookings form protected by reCAPTCHA, or some mechanism to ensure submission of the appointment request form is made by a human vs. bot?
                                                                                                        • Zoho Books | Product updates | May 2025

                                                                                                          Hello users, We’ve rolled out new features and enhancements to elevate your accounting experience. From configuring approval at the module level to allocating landed costs to multiple bills, these updates are designed to help you stay on top of your finances
                                                                                                        • Zoho Notebook suddenly running very slow on long notes

                                                                                                          I have been a longtime user of Zoho Notebook. Historically, it has run quite well, but I've noticed over the last few days that it has begun to run unbearably slow when typing in large notes, to the point where I can type four words and have to wait for
                                                                                                        • Multiple team members to access one office PC

                                                                                                          Hello, We have a high-performance PC in our office that we use for resource-intensive tasks. All team members need to remotely access this PC from time to time. However, when I enable remote access for myself through Zoho Assist, the PC does not appear
                                                                                                        • Zoho Bookings API, timezone is not recognized when passed

                                                                                                          Has something changed? Time zone is being passed through API but it is NOT being recognized. response is not showing time zonetime that was passed through request. This is an URGENT issue as it is preventing bookings! Seems like this is due to a recent
                                                                                                        • Can I view a gallery of attachments related to an Account, Contact, or Subscription

                                                                                                          It is often useful to review photos related to an account or contact by service type. It would be nice to be able to see the photos collected through workorders or appointments all associated.
                                                                                                        • View Kanban tasks in "Status" layout for all projects

                                                                                                          Hi I'm testing Zoho Projects Express to see if it is suitable for my business. So far it looks great and seems to do everything we want (except critical path on the Gantt charts), but one thing I can't seem to figure out is this: If I go into a project, and choose "Kanban", I can select the "Status" layout which is great. I can see the status of all of the tasks in that project, and who is working on what. However, if I go to: Home > My Tasks > Kanban, then the "Status" layout isn't an option - only
                                                                                                        • Unsubscribe Page

                                                                                                          Where in Zoho Campaigns can I go to customize the design and copy on the unsubscribe page and follow-up "thank you" page? I am not seeing it under Settings.
                                                                                                        • Ability to modify what displays in calendar invite?

                                                                                                          I am a long time calendly user and want to make the switch to bookings.  I understand that there is not currently a meets/hangouts integration, is one on the roadmap? Is there anyway I can modify the calendar invite to include the meet link?  I can add it to the emails no problem, but I would also like it to display on their calendar.  Is there some work around I can do to get it on the calendar?  Also am I able to modify the calendar event title?
                                                                                                        • Bookings page very slow to load

                                                                                                          I recently switched to Zoho bookings from calendly and yesterday I switched back. Zoho Bookings page was taking 7-23 seconds to load. We were losing paid clicks from Google because they had to wait too long. Does anyone have any suggestions?
                                                                                                        • Zoho Bookings: How to set a limit for maximum bookings per day?

                                                                                                          Let's say I have 1 hour slots OPEN for an entire day. What if I want all of the OPEN slots to turn OFF if/when I hit a certain number of total bookings for that day? I usually only want a total of 5 appointments to be booked but I'm not sure of the exact
                                                                                                        • Zoho Booking API to update service for Assigned Agent

                                                                                                          Hi there, I have been testing and looking at the Zoho booking API for the Assigned Agent update from Zoho CRM for a long time. There is only a Fetch service request, but no updated Assigned Agent options. Does anyone know how to do that? PS: I can use
                                                                                                        • Zoho Accounts and Book Keeping candidate required

                                                                                                          Urgently required data operator who can do following tasks: Purchase Bill Entry Sale Bill Entry Bank Entries Cash Book entries 40-75 entries per days
                                                                                                        • Cancellation waiting list - Zoho Bookings

                                                                                                          Is it possible to have a waiting list in case I got a cancellation it can be filled automatically with people on this list? 
                                                                                                        • Zoho Bookings Integration with Make.com

                                                                                                          Dear Zoho Bookings Support Team, We are writing to request a new integration between Zoho Bookings and Make.com, a leading automation platform widely used by Zoho users. Current Integration: We acknowledge the existing integration with Zapier, another
                                                                                                        • Different Page Numbering

                                                                                                          I want the page numbers not just 1,2,3... but i,ii,iii,iv,... or even I,II,III,IV.... How can I do this?
                                                                                                        • Leads Should Support Business-Centric Structure for B2B Use

                                                                                                          We’re a B2B company that generates leads for other businesses and often engage with multiple contacts within the same company. For years, we’ve struggled with Zoho CRM’s limitation of requiring a Last Name field for leads. For example, if we’re pursuing
                                                                                                        • Currency Data Type Issue

                                                                                                          Hi, I'm running into an issue with the currency data type conversion with the pipeline tool inside Zoho Analytics. Basically, when the table is added to the pipeline, the columns with currency data type will be converted to text type. I assume it's because
                                                                                                        • Zoho AI Translate – No Support for Hebrew?

                                                                                                          I want to use Zoho AI Translate, but I see that it does not support Hebrew. Since Zoho supports multiple languages, I was hoping this function would also work with Hebrew. Is there any plan to add Hebrew support in the near future? Or is there an alternative
                                                                                                        • Exclude Segment from Campaign Recipients

                                                                                                          I've created two Segments in order to separate Non-Marketing Contacts from Marketing Contacts. I'd like to send an Eblast to all Marketing contacts in my lists, but when I go to select Recipients, I have two options: 1. To Choose Lists to Send to; 2.
                                                                                                        • Equivalent domains

                                                                                                          Need a settings feature for adding/modifying/deleting domains that use the same login service. The feature can also suggest some popular sites that use shared credentials to access domains under their control. For example: amazon.com and its local variations like amazon.in. For example: gmail.com and google.com. LastPass has this feature.
                                                                                                        • Can't verify DKIM key?

                                                                                                          So basically I just wanted to verify the email on my domain so it doesn't showup as spam in other people's inboxes. So I did what Zoho told me to do, it was to verify a DKIM key. I created the key with the address, added the correct information to the TXT file in my domain's DNS settings, tried to verify it and it keeps saying 'Verification failed'. I tried it more then once, I reset the DKIM key, and for some reason it just won't verify. Either it's me being impatient or this thing isn't working.
                                                                                                        • Forecast performance analysis

                                                                                                          Last modified on 15/05/2023: Performance analysis in forecasts is now available for all Zoho CRM users in all DCs. Note that it was an early access feature available only upon request. As of May 10, 2023, it is rolled out for all Zoho CRM accounts. Find
                                                                                                        • Audio/video quality issues with Zoho Meeting – Any roadmap for improvement?

                                                                                                          Hi Zoho Team, We’ve been using Zoho Meeting for both internal and external meetings, and unfortunately, the experience has been consistently poor. The video and audio quality are so unreliable that it often renders meetings ineffective—especially with
                                                                                                        • Clone a Module??

                                                                                                          I am giong to repurpose the Vendors module but would like to have a separate but very similar module for another group of contacts called Buyers. I have already repurposed Contacts to Sellers. Is it possible to clone (make a duplicate) module of Vendors
                                                                                                        • Deleting Records Older Than 14 Days

                                                                                                          I have a form called vacancies that contains a field "status_date". I need to create a schedule that runs once a week and if the status date is > 14 days it deletes that record.  I would appreciate anyones help.  -Aaron 
                                                                                                        • I need open my email in Zoho from oulook account

                                                                                                          Hi Can you help me to solved this First, I’m unable to access my email account via Outlook. Second, when I send any email from my Zoho account, it doesn’t reach Gmail inboxes. Thank you for your support
                                                                                                        • Default value for Subject field in Case module

                                                                                                          I would like to add a default value to the Subject field in a custom module based on the Case module. Since this field is mandatory, I can't use a workflow rule that adds a default subject if the field is left empty. So I would like to display a default
                                                                                                        • Next Page