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

                                                                                                    • setting owner of note when adding via deluge

                                                                                                      My organization has requested the ability to mass update the notes related list in the deals module. Since this can't be done with the mass update feature, I created an update "notes single" line field and created a workflow rule that triggers a function
                                                                                                    • Approver

                                                                                                      I noticed that this year, the leave approver for all employees has been changed to the portal admin. How can I revert this and set myself as the approver again, as I was previously?
                                                                                                    • Recurring Bookings

                                                                                                      Will Zoho Bookings ever offer an option to the customer to schedule recurring meetings (unlimited) for the same days/times? Making a client schedule the same days/times for an entire month is a tedious process. I'd like to offer the option upfront to
                                                                                                    • How do we add Google Analytics code to Zoho Bookings scheduling pages or the thank you page?

                                                                                                      We need to track user activity on individual Bookings' pages and/or the thank you pages? How do we do this?
                                                                                                    • Add Image Upload Field to Zoho Bookings Registration Form

                                                                                                      Hi, We would like to request the addition of an image upload field to the Zoho Bookings registration form. Currently, Zoho Bookings only supports text-based fields (e.g., Single Line, Multi-Line, Email, Checkbox, Dropdown, Radio Button, and Date), but
                                                                                                    • Bookings duration - days

                                                                                                      Hi team, Is there any way to setup services/bookings that span multiple days? I am using Zoho Bookings for meeting room bookings. Clients may wish to book a room for more than one day, for up to a month.  If not, is there a plan to allow services to be setup with durations of Days as well as hours and minutes? Many thanks, Anna.
                                                                                                    • Bookings Sync with Zoho Calendar Breaks Again and Again

                                                                                                      I have documented notes since June 2019! The sync between Bookings and Zoho Calendar continues to break at random times. We are nearly 3 years later and still have sync problems pop up randomly! As I type, it's broken again. I have been a stubborn client
                                                                                                    • Can't Reschedule appointments

                                                                                                      Hi,  I am attempting to reschedule all appointments for this week from one Trainer to another. I have made sure the time is available in the Trainers calendar we are moving the appointments to but whenever I go to reschedule the appointment it still comes up saying the trainer has no available time at all this week.  The next appointment is Wednesday 11am so need to get it switched over ASAP!! Thanks
                                                                                                    • 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
                                                                                                    • Calendar view - All-day with date-time fields

                                                                                                      Hi friends, I have a calendar view that is showing records based on e.g. start-time and end-time, both of datatype date-time. I couldn't figure out of to show "all day records" in the all-day section of the weekly and daily views. Trying to set start-time/end-time to e.g.  15-10-2012 00:00:00 was not helpful. What else should I try please? Kind regards, Idan
                                                                                                    • Zoho CRM Tags not carrying over to Zoho Campaigns

                                                                                                      We would like to create Campaign Segments and/or Lists based upon tags given in Zoho CRM, but we are unable to figure out how to do it. For example, if a customer is tagged "Residential" we would like Zoho Campaigns to create a list or segment based on
                                                                                                    • Zoho Bookings Not Showing Allocated Time Slots

                                                                                                      Hi, I have a real problem at the moment with Zoho Bookings not showing any available time slots and really not sure why this is happening. Could Someone from support please investigate. I have gone through all of my settings and calendar integration and can't see what the problem is. WOuld welcome some support please. https://zoho-tony1709.zohobookings.com/#/customer/coachcurl https://zoho-tony1709.zohobookings.com/#/customer/tagb Tony
                                                                                                    • Attention: Important updates to the payment gateway integrations

                                                                                                      Greetings from the Zoho Bookings team! We have a few important updates to the payment gateway integrations that allow you to collect online payments for your appointments. The following payment gateways will be updated, and we encourage you to make the
                                                                                                    • Multi Day booking for resources

                                                                                                      I have following business-case: Rental for Tablets. Customer should be able to select how many device for how many days he'd like to rent. Same as a car rental for multiple days. Is this possible with Bookings on the current version?
                                                                                                    • Export Options

                                                                                                      Hi, In calendar, List view, there is an option to show or hide fields, and we export this view daily, and use it to create a Gantt type chart for the days bookings. It would be SUPER helpful (and time saving) to be able to export the Notes and or Custom
                                                                                                    • Tip #3: How to change your booking page language

                                                                                                      Displaying your booking page in your target audience's language can greatly increase customer satisfaction. By speaking their language, you will help customers feel more comfortable scheduling with you and create a stronger connection with them. Let's
                                                                                                    • Ability to Set Text Direction for Individual Cells in Zoho Sheet

                                                                                                      Dear Zoho Sheet Team, We hope you are doing well. We would like to request an enhancement in Zoho Sheet that allows users to set the text direction (right-to-left or left-to-right) for individual cells, similar to what is available in Google Sheets. Use
                                                                                                    • Create Google meet link for a group

                                                                                                      Hello, in the company that I work, we have been using calendly to create a consultation where more than one person can schedule at the same hour and day. I've been trying to implement it on zoho bookings and I don't know if it is possible. In my tests,
                                                                                                    • Link for booked scedule on invitation

                                                                                                      I hav installed some sites for booking appointments in the booking app ... but tht invitation does not contain a link to the meeting software e.b.ZOOM, Google Meet or Teams ... how do I fix this?
                                                                                                    • Zoho Desk integration with Power BI

                                                                                                      Hi, I want to be able to create a Power BI report which has live updates of ticket data from zoho desk, is this possile at all? Thanks Jack
                                                                                                    • Implement Meeting Polls in Zoho Bookings

                                                                                                      Dear Zoho Bookings Support Team, We'd like to propose a feature enhancement related to appointment scheduling within Zoho Bookings. Current Functionality: Zoho Bookings excels at streamlining individual appointment scheduling. Users can set availability
                                                                                                    • zet pack not working

                                                                                                      We are using the zet pack command to package our Zoho extension. However, after running the command, the extension gets packed, but the resulting package is empty. We've attached a screenshot for reference. Could you please assist us with resolving this
                                                                                                    • Adding number of days to an estimate.

                                                                                                      I need both QTY of item and "number of days hire" in my estimates at the line item level. Any clues as to how this is done would be greatly appreciated. It needs to calculate. Thanks J
                                                                                                    • Guided Conversation History Does Not Show in Ticket Submission

                                                                                                      Hello, An issue I've noticed is that once a user steps through the 3-5 questions on the guided conversations bot that raises a Zoho ticket for them, the history of the selections do not show on the ticket. It would be beneficial if the ticket could include
                                                                                                    • Function 58: Custom calculation in item table of invoices (2 fields)

                                                                                                      Hello everyone, and welcome back to our series! In Zoho Books, the Item Amount in invoices is calculated by multiplying the Quantity and Rate fields. Previously, we shared a function to include a custom field in this calculation. Today, we are taking
                                                                                                    • Re-assigning a user account

                                                                                                      I’d like to reassign an existing Zoho One user account (for a member of staff that is no longer working for the company) to a new member of staff that is joining the company. If I do this will we lose the emails associated with Contacts in the CRM for
                                                                                                    • How to Add a Contact to a Campaign Using Deluge Script

                                                                                                      Hi ZohoCommunity, I need help with adding a contact to a campaign in Zoho Campaigns using Deluge script. Specifically, I want to automatically add a contact to a campaign when the campaign name field in the contact information is filled. This field is
                                                                                                    • Creator to WorkDrive workflow | Missing "Upload file" WorkDrive action in Flow or not?

                                                                                                      I am trying to build a Creator app with a form through which files can be uploaded to WorkDrive and simultaneously added to a Creator database. As far as I understood, automating this Creator-WorkDrive workflow can best be done with Flow, offering greater
                                                                                                    • Issue with Zoho CRM DELUGE Search – No Results Returned

                                                                                                      Hi, I’m trying to run the following code, but it returns nothing. I have 4 records where the Next_Date field has the value "OK". I tried changing the date format to different types, like "2025-01-01", but I still get no results. Can you help me understand
                                                                                                    • Subform Bug during Approval Process

                                                                                                      If a field is editable during the waiting stage of an Approval Process and a record is modified, the subform glitches. Steps to reproduce: In the Approval Process, allow a field to be modified while waiting for approval. Edit the record during this stage.
                                                                                                    • How to get Created Time of a Record in Client Script

                                                                                                      In the record details I can see created time under the Created By I am trying to get the Created Time in the API Request var id = $Page.record_id; var res = ZDK.Apps.CRM.Price_List_Item.fetchById(id); log(res.Created_Time); In the JSON Response I cant
                                                                                                    • Google Maps API integration into Forms

                                                                                                      I looked around a good bit and could  not find anything on this topic. I was curious about using the Google Maps API on a Zoho Form. Specifically an order form for a product that we will only deliver within certain City Limits. We currently use the API to call the exact address (as dictated by Google) and if the City name does not match where we service it is very evident. (Using FormCraft Form in Word Press) The "exact address" name is also used later in the process as well.  I do not see a way
                                                                                                    • Global Search Custom Field

                                                                                                      I need to be able to search a custom field within a lookup field (see attached screenshot). The custom field will not glean any results
                                                                                                    • CRM Quotes- Delete tasks when status is changed

                                                                                                      Hello. We have our quotes setup for approval process. We would like however to delete the tasks that are made when a different quote stage is selected. So when a quote stage is setup for "sent for review" we have the automation process to send out an
                                                                                                    • Public links for WorkDrive files

                                                                                                      Our company is considering building an app with Creator that allows one to upload files into the WorkDrive through a Creator form, simultaneously collecting information for a content database in Creator. Ideally, we'd like to centralise the entire workflow
                                                                                                    • Can't add company logo and favicon as a superadmin

                                                                                                      I am logged in as the superadmin but can't add company logo and favicon - the fields are greyed out. Any idea as to what the problem could be?
                                                                                                    • Bulk Update API

                                                                                                      I’m reaching out to see if anyone has updates on the bulk records feature release. We’re eager to leverage this functionality for our operations, but until it becomes available, our current API call limits are proving to be a bottleneck—even after upgrading
                                                                                                    • Zoho Flow Debugging

                                                                                                      Hello I built a custom function that takes input via a webhook trigger into the flow. The custom function has input as strings and I have one single line that info each of the variables to debug. However, for each of the tests (instances of webhook triggers)
                                                                                                    • Unable to Send Ticket Reply as a Contact in Zoho Desk?

                                                                                                      Hi Zoho Desk Team, I am trying to send a reply to a ticket on behalf of a contact using the Zoho Desk API. My goal is to have the contact's response reflected in the ticket conversation, but I am facing an issue where only the ticket author can comment.
                                                                                                    • Problem with currency field in Zoho CRM

                                                                                                      Hi Guys Zoho Books has a feature in currency fields that automatically converts decimal numbers with commas ( , ) to period format ( . ) when pasting them. For example: R$ 2,50 --> R$ 2.50 Is this behavior available in Zoho CRM? I couldn't find any configuration
                                                                                                    • Next Page