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!


    • Recent Topics

    • Zoho CRM API, Python SDK v7 Quoted_Items

      Hello. How do I use this SDK to retrieve the Quoted_Items from a Quote and downstream the items in a Sales Order I can see references to a constant INVENTORY_MODULES_ITEMS = ["invoiced_items", "quoted_items", "purchase_items", "ordered_items"] But I cannot
    • 【Zoho CRM】数式項目に関するアップデート

      ユーザーの皆さま、こんにちは。コミュニティチームの中野です。 今回は「Zoho CRM アップデート情報」の中から、数式項目のアップデート(3つの機能強化)をご紹介します。 【目次】 1、時間ベースの数式を自動更新とリアルタイムの値を表示 2、条件に基づいて数式の実行停止 3、既存の数式を使用して新しい数式を作成 1. 時間ベースの数式を自動更新とリアルタイムの値を表示 数式項目のプロパティに関数「Now()」を含む数式項目の値をリアルタイムで自動更新するというチェックボックスを導入しました。 Before:データが手動で編集されるか、自動化によって更新されたときにのみ、数式項目は最新の結果を計算し、値を表示していた。
    • Issue with syncing zoho campaigns with zoho crm

      Hi there, I want to sync both zoho campaigns with zoho crm however i have encountered some issues with this. when clicking manage in zoho i receive this message even though im using the same account and its an admin account. however when i go to zoho
    • Changing Color Theme of Guided Conversations

      Hello, We have recently added Guided Conversations to one of our websites, but I am wondering if there is a way to customize the color scheme so it matches the appearance of the website? Thank you in advance!
    • The ability to show fields from subforms when viewing from related list

      Hi there, Currently im only able to display default columns , however when im unable to add the columns/fields from the subform Ive created. below is a field called quantity from the subform. Im not able to search up this field from the manage column
    • HTML Email in Zoho Books

      Is it possible to create custom html email template in zoho books. 
    • Recording overpayment?

      So a customer just overpaid me and how do I record this? I can't enter an amount that is higher than the invoice amount. Eg. Invoice is $195 and he sent $200. He's a reccuring customer so is there a way to record so that he has a $5 advance for future invoice?
    • How can I add Material cost to a project?

      Hello, We use Zoho project to manage scheduled work. This consists in labour tasks and matrials cost. How can I add the material budget, then teh cost to the project? Thanks Barbara
    • Bigin-Zoho Projects Integration

      We're pleased to announce the Bigin-Zoho Projects integration, which enables you to manage client relationships and project tasks simultaneously in one system. With this integration, once you close a deal in Bigin, you can create a project in Zoho Projects
    • Managing independent contractors

      We use Independent contractors as our field techs. I'm looking for a solution to be able to manage there timesheets, payments, and etc
    • License Issue

      Hello Campaigns Team, we have 17 ZOHO One licenses but in campaigns I get the message that we have a free plan. How can we use ZOHO campaigns? As far as I understood campaigns is a part of ZOHO One. THX Niels
    • Dynamic Date Filtering for KPI Widgets – Need Help with Query Table

      Hello, I'm seeking help with setting up dynamic date filtering for my KPI widgets in Zoho Analytics. Below is an overview of my setup and the issues I'm facing: Why: I need my KPI widgets to update dynamically based on a date range selected via a dashboard
    • Count Function in Zoho Table

      Hi Zoho Team, Hope you're doing well. We would like to request the addition of a Count function in Zoho Table, similar to what exists in Excel, Google Sheets, and Airtable. Currently, there is no built-in way to count the occurrences of unique values
    • Leads, Prospects, Contacts, Clients and Me

      I'm trying to adapt my process to Zoho and am getting confused. Here's how I did it before. Maybe it's just terminology...? Leads - anyone from any source that I might want as a client. Leads include people that I am sending emails or tapping in social
    • Contacts, Leads, Prospects, Opportunities, Deals, Oh my!

      I've implemented three CRM's in previous companies, and led the effort for two of those.  I'm pretty familiar with sales pipeline management. For my current company, I chose Zoho One because of the broad range it includes for other business processes, and am generally quite happy.  So now it's time to dig into Zoho CRM And I find myself a bit befuddled. In other implementations, a "Contact" was just that- a name and some contact information.  Could be anybody whether interested in doing business
    • Visual Sync Status Indicator

      I think I've see in documentation that WorkDrive had the industry standard of indicating a sync status for individual files and folders. I'm just starting with WD and synced my first test folder, but there was no way to tell what's happening by just looking
    • Is there a way to make the new tab button open a new cloud document?

      I'm coming from Google Docs. Plus, is there any way to have a set a default font? I'm using the desktop app and I prefer the options I can get through the cloud documents. I want the convenience of just opening a new cloud document rather than doc that's
    • Tip 26: How to hide the "Submit" button from a form

      Hi everyone, Hope you're staying safe and working from home. We are, too. By now, we at Zoho are all very much accustomed to the new normal—working remotely. Today, we're back with yet another simple but interesting tip--how to hide the Submit button from your forms. In certain scenarios, you may want to hide the submit button from a form until all the fields are filled in.  Use case In this tip, we'll show you how to hide the Submit button while the user is entering data into the form, and then
    • Trying to export a report to Excel via a deluge script

      I have this code from other posts but it gives me an error of improper statement, due to missing ; at end of line or incomplete expression. Tried lots of variations to no avail. openUrl(https://creatorapp.zoho.com/<username>/<app name>/XLSX/#Report:<reportname>,"same
    • Bigin_Email Notification not being sent when a new lead is created

      I have a workflow in BIGIN set to send an email notification when a new lead is created via a webform (integrated with ZohoForm) The trigger is whenever a contact is "Create or Edit". Conditioning was applied for contacts which source is "Website" If
    • ZOHO CRM API Python SDK Convert Quote to Sales Order

      I can see footprints that this may be possible through Inventory Conversion. But I am unable to locate any specific details or samples on how to do this. I am using the most current Python SDK. Any support or even sample code would be much appreciated
    • Displaying Notes/Description Columns in "All Expense" showing Tabs

      It's surprising to see there is no option to view description columns in tab showing all expenses. There are provisions for Reference# and Status, but why not the description/notes. Please Add. Thank You.
    • Zoho Books - uploading company logo squashed

      I am trying to upload my company logo with the following dimensions - 240 x 240 pixels and a file size of 106Kb. When I look at the logo in my invoices, it is squashed and not the right size. Any idea what is going on? I've tried uploading jpeg and png
    • Petty cash discrepancy

      How do I record a petty cash discrepancy? We had money go missing and need to document that in the books, but I'm not sure how to put that in. It's not an expense, just a loss of cash.
    • Missing Custom Fields in ZOHO Reports

      Hi, I am currently attempting to generate some reports using the programme. However, I have met some obstacles in the form of missing custom fields from the field selection panel when creating charts etc. Please advise. There are plenty of custom fields which is rather important to creating these reports. Thank you.
    • Zoho Workdrive file versions

      Hello. I have Workdrive setup to sync files offline to an external hard drive. The off line sync folder currently shows at 1.42 TB. I have a 5 TB storage limit in Workdrive. The cloud version of Workdrive says that I have used all 5 TB! I have 27, 285
    • Integration with Zoho CRM?

      Will it be possible to integrate WorkDrive with CRM similar do Zoho Docs?
    • How to control the # of version of files to keep?

      Currently most of the WorkDrive Storage comprise of the many versions of files saved. How do I save some space and reduce the number of version of date or files saved in WorkDrive? Thanks
    • Should I Use Zoho Mail Calendar, or Zoho CRM Calendar, or Zoho Calendar?

      After a couple of dozens Zoho solopreneur products that I transitioned to after becoming a Zoho One enthusiast 5 years ago, I am finally preparing to conquer the remaining two bastions: Mail and WorkDrive (using Google Workspace at the moment). A NYC
    • Add comments to a form

      Hello, I'm trying to add comments to a form using a subform with one field named comment, but I don't want prior comments to be editable or deleteable by anyone (except the admin).  Is there a way to only display prior comments (with a datetime, user and comment field preferably) but still be able to add new ones when editing the main form?  I'm not tied to subforms if there is an easier was to do this?
    • Zoho Books | Product updates | March 2025

      Hello users, We have rolled out new updates in Zoho Books to enhance your accounting experience. These include the ability to create workflow rules for manual journals and Multi-Factor Authentication (MFA) for customer and vendor portals. Explore these
    • Work Drive Tray Icon Missing

      How can I get the tray icon back? The app froze, had to restart PC and then it's been gone since...  I've re-installed the windows program and restarted my machine twice now.
    • cant receive emails

      I have checked the Dns and everything seems to be fine pls check the print screens attached below help me cause i need to solve this fast
    • Retainer invoice in Zoho Finance modlue

      Hello, Is there a way of creating retainer invoices in the Zoho Finance module? If not can I request this is considered for future updates please.
    • iOS Widget Not Working

      It appears that the iOS widget is not working, displaying a blank white screen instead of a selected note. I’m using app version 6.5.12 and iOS 18.3.1.
    • Two Problems With Data Imported to Notes

      Occasionally I want to create a note by copying and pasting a few paragraphs from an article on line. When I create a new note and paste in the section the newly created note winds up with each paragraph in white text on a dark background rather than
    • Unable to send message;Reason:550 5.4.6 Unusual sending activity detected. Please try after sometime

      Hello i'm unable to send any email because i keep getting this error Unable to send message;Reason:550 5.4.6 Unusual sending activity detected. Please try after sometime i have literally sent less than 10 emails today i'm not sure why i'm getting this
    • 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
    • Generate a link for Zoho Sign we can copy and use in a separate email

      Please consider adding functionality that would all a user to copy a reminder link so that we can include it in a personalized email instead of sending a Zoho reminder. Or, allow us to customize the reminder email. Use Case: We have clients we need to
    • How to associate a document sent in Zoho Sign with an deal in the CRM?

      Hi, often documents are loaded in Zoho sign and sent for signature. These sometimes are linked to a deal in the Zoho CRM and would be nice to see the status of the document within the CRM. I am aware of the integration, but that assumes that the document
    • Next Page