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!


    Nederlandse Hulpbronnen


      • Recent Topics

      • Prevent subform editing on a module's detail's page

        Hi everyone, We would like to prevent any editing of the subform data in the : Create page Edit page Details page (as subform editing is now allowed by the recent UX update) We are able to prevent editing by making the subform fields read only in the
      • CRM x WorkDrive: File storage for new CRM signups is now powered by WorkDrive

        Availability Editions: All DCs: All Release plan: Released for new signups in all DCs. It will be enabled for existing users in a phased manner in the upcoming months. Help documentation: Documents in Zoho CRM Manage folders in Documents tab Manage files
      • I'm so confused by the new (?) look

        I've been off Notebook for a long time, neglecting the app and never visiting the website. I decided to renew my commitment to it. It looks completely different! When I logged on before (app or browser page) I'd see a very pretty display of my multiple
      • Custom CSS in Zoho Form

        Hi, Please let me know, how we can add custom css in Zoho Form.  Thanks
      • Deluge Script to Reopen Ticket if Tasks are not Completed

        I have the following script, my goal is to have it automatically reopen the ticket when the ticket is closed if there are Activities assigned to the ticket that are not "Completed". This script seems to reopen the ticket if there are any tasks at all,
      • Zoho Desk & Tasks

        Hi, I'd like to be able to create a set of tasks each time a customer request comes in, as I understand it, currently each would need to be create manually. Project is too much of an overhead for what we want to use. Effectively in various use cases we
      • Export all Zoho desk tickets for past 3 months

        Hi I need to export ticket data from Zoho Desk. Specifically, I'm looking to: Export the last 3 months of tickets⁠ include ticket categories, timestamps, resolutions, agent responses (basically as much data as possible) the ticket content being the most
      • Zoho CRM <> Zoho Desk Account Sync

        I have had custom fields in Zoho CRM for a time and would like that data to sync to Zoho Desk. However, since the accounts are all synced to Zoho Desk already, the newly mapped fields are not updating in Zoho Desk. Is there a way to force the sync to
      • 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
      • Configuring ZMA Webhook for Zoho Flow : Missing Key Information Error

        I'm looking to send a webhook to Zoho Flow at the end of a Marketing Automation journey in order to perform more actions that I can't do with just a journey. I have the Webhook created in Flow and set up in ZMA, however when I test it I get the error
      • Zoho Billing Record Refund vs Refund

        When looking at a paid invoice, the payment record can be viewed. In the more actions, there is a "Record Refund" option. If you click the payment referernce you see a "Refund" option. They bring up different forms. It appears as if "Record Refund" is
      • Emoticons to Slack in Zoho Flow

        When using the Slack integration in Zoho Flow, is there a way to send emoticons in the message? When I tried :emoticon: it didn't translate it to the emoticon.
      • Unified WhatsApp Number Management in Zoho Desk and SalesIQ

        Dear Zoho Desk Support Team, We are currently utilizing both Zoho Desk and Zoho SalesIQ for our customer support operations. While both platforms offer WhatsApp integration, we are facing challenges due to the requirement of separate WhatsApp numbers
      • Set connection link name from variable in invokeurl

        Hi, guys. How to set in parameter "connection" a variable, instead of a string. connectionLinkName = manager.get('connectionLinkName').toString(); response = invokeurl [ url :"https://www.googleapis.com/calendar/v3/freeBusy" type :POST parameters:requestParams.toString()
      • How to set default filter to CRM integration field

        I have a products subform in my order form and I'm using the CRM integration field to connect the Products module from my CRM to this subform. I want to filter the data that is fetched to the field from the CRM based on a status field in the Products
      • Restore Report in Zoho Creator After Changing Report Type

        I created a report in Zoho Creator and have been using it regularly. While editing, I accidentally changed the report type, and all the fields disappeared from the report. I am using the development version, but I don’t want to revert all the changes
      • Zoho Creator Upcoming Updates - March 2025

        Hello everyone, We hope you’ve had the chance to explore Release Projection 1 for 2025! This month, we’re keeping up the momentum by bringing even more powerful features and enhancements to Zoho Creator. Here's what you can expect in March: App menu builder
      • Why can't you make a layout rule based on a lookup field?

        Hello :) I am wanting to build a layout rule based on the selection of a lookup field. I have 3 fields that I want to hide for all options, but only show one if the lookup is one of the 3 options needing the extra field. It doesn't seem to give me the
      • Client Script | Update - Introducing Subform Events and Actions

        Are you making the most of your subforms in Zoho CRM? Do you wish you could automate subform interactions and enhance user experience effortlessly? What if you had Client APIs and events specifically designed for subforms? We are thrilled to introduce
      • 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
      • Why Sharing Rules do Not support relative date comparison???

        I am creating a Sharing Rule and simply want to share where "Last Day of Coverage" (Date field) is Greater than TODAY (Starting Tomorrow). However, sharing rules don't have the option to compare a date field to a relative date (like today), only to Static
      • How to add "Forever Free Plan" to existing mail lite plan?

        There's an offer for: "Up to five users, 5GB/User, 25MB attachment limit." I already have a mail lite plan. I really like zoho mail and would like this added but I can't seem to access it. Keeps redirecting me to my existing inbox when i click the o
      • i can't create other user with my lite plan

        hello, I have paid little plan and I have added two domains but each has its own user however zoho shows me this message You do not have enough licenses. Purchase the necessary licenses to add, invite or import users I don’t know why if I have another
      • Zoho Books & Zoho CRM - Funcionalidade do campo moeda

        Pessoal bom dia, O Zoho Books tem uma funcionalidade nos campos de moeda, que ao colar números decimais com vírgula ( , ), ele automaticamente transforma para o formato de ponto ( . ). Ex: R$ 2,50 --> R$ 2.50 Esse comportamento está disponível no Zoho
      • Does Mail Lite allow SMTP?

        I am looking to use SMTP access, however I am not sure what plan I have to purchase, please assist.
      • No image image comes out in the recipient when I sent an email

        Hello to the entire forum, when I send an email from Zoho, my profile picture does not come out. On the other hand, if you do, using Gmail accounts. How is it configured to leave ??? Thank you Greetings !!
      • Iphone receipt capture stopped working

        I have been having difficulty getting receipt capture to work on the iPhone app. I have been using a work around by taking a photo with my camera then uploading it into the app instead of taking the picture through the app. This adds way too much extra
      • 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
      • Create View to See Tickets Closed within the last 3 days

        I'm trying to create a view in Zoho Desk that shows me "recently closed ticket," which I will define as tickets closed in the last 3 days. I want this view to update so that whenever I click to view it is recalculates and shows me tickets closed within 3 days from that moment. When I try to Create a view and use the criteria of "Ticket Closed Time" I have to specify a discrete time frame (on or before a specific date). It doesn't allow me to define time/date dynamically like I can do with date fields
      • ERROR 554 5.1.8 Sender Address Blocked code(554)

        We have an email with Zoho ( comercial@bruiser.com.br), but, when we try associate the account in GMAIL, the server shows this message:  554 5.1.8 Sender Address Blocked code(554) I see this error appear when the limits of returns exceded 10 messages,
      • 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
      • IP Addresses for Whitelist

        Hi,  Where can I get a list of the IP addresses I need to whitelist for accessing Zoho Desk? TIA
      • 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?
      • Rejected Accounts still listed for Deal

        Hello guys I have a approval process thats validate the Accounts in CRM The issue is even when a account is rejected you can open a deal with it It's not supposed to appear in the lookup field or the approval process become pointless Can you guys help
      • Zoho Rentals

        Team, Zoho Inventory provides great features for Retail Sales and Purchases. On a similar note, There are significant portion of Rental industry would be missed out, if not looked into. Can we have a Zoho Rentals which can integrate with Zoho Inventory? Thanks!
      • 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
      • How can I view Help Center articles in 'Sandbox' mode?

        I have published some help center articles but when I try to preview the knowledge base page, it says 'We have no content to display'.
      • Zoho Books API down

        We've been using the zoho books api for the last few weeks to pull open invoices, and the code has stopped working suddenly. When making the same API call as always, we're getting a 400 error.
      • Loop in Blueprint but it works. Why? How should this be set?

        see picture
      • Introducing Keyboard Shortcuts for Zoho CRM

        Dear Customers, We're happy to introduce keyboard shortcuts for Zoho CRM features! Until now, you might have been navigating to modules manually using the mouse, and at times, it could be tedious, especially when you had to search for specific modules
      • Next Page