You could add Client Script through two ways:
1. Through Setup Page:
Navigate to Setup (⚙️) in Zoho CRM >> Developer Hub >> Client Script >> New Script.
-> Provide a Name & Description appropriate to script
-> Category Details -
- Select Category based on requirement. Module - triggers via Events || Commands - triggers via Command Pallet/Shortcut Keys.
- Choose Module where you want to add script. i.e., Lead, Contact, etc.
- Choose Page to deploy script in specific page. i.e., Create, Edit, Clone, Detail, List, etc.
- Choose Layout. i.e., Standard or Custom layouts.
-> Event Details -
Select Event Type - Field Event or Page Event or Subform Event
- Field Event -> Select the Field & Event (i.e., onChange on First Name field).
- Page Event -> Select the Page & Event (i.e., onLoad on Create Page).
- Subform Event -> Select the Subform & Event (i.e., onCellChange).
2. Through Detail/List/Create/Edit/Clone Pages of a Record in Module
-> Choose a desired module in Zoho CRM, and open either the List, Create, Detail, Edit or Clone page of any record in that module. For example, consider the Create Lead page.
-> For Pages (such as Create/Edit/Clone) - In the right-most corner of the page, click Client Script. Then, Add script.
-> The Category details will be pre-populated by the system. Fill in the other details of the client script, such as Name, Description, Event Details of the client script. Further, click next and add your script to the code editor in Client Script IDE. Then click Save and Close.
Add Client Script via Detail Page:
Add Client Script via Different Pages such as List/Create/Edit/Clone:
TIPS: How to Optimize the Code in Client Script
It is essential to write code in an optimized way to ensure smooth execution and avoid potential errors when working with Client Scripts in Zoho CRM. This also helps to enhance performance, maintainability, reduce unwanted API calls and a well-structured code with optimal logic.
Avoid Repetitive Code
-
> Client Script supports a standard sub-feature called "Static Resources". It provides an easier way to import existing code files in the form of static resources and use them in your script. You could upload a Javascript file as a static resource, include the uploaded file in your script using the Add button on the right panel of the Code Editor, and call the function in the static resource file from your script whenever it is required. Refer to Static Resources in Client Script for more information.
Use default ZDK Client methods and Web CRM API
-> Client Script provides ZDK (i.e., Zoho Developement Kit) libraries with various default built-in methods, which help users to make the business process in more efficient way within Zoho CRM. Using these readily available methods, we can perform default actions such as showing pop-up/alert, fetch/update record data instantly, fetch logged-in user's/Org's information, etc. Learn more about Client API with samples.
-> Similarly, we support various Web CRM methods that serve as wrappers of the Zoho CRM REST APIs, and users can use them directly within Client Script and make the necessary actions within Zoho CRM. Refer to CRM API for more information and direct samples. Minimize Web API calls within Zoho CRM
-> Every Web API will consume an API credit, same as mentioned for Zoho CRM APIs used within Custom Function/Developer Tool/Third-party system. For example: fetchById (Web API) consumes the same credits as per 'Get Record' CRM API. Whereas, the Client API will not consume any credits, as it's a UI action on the client end. Excess API calls (or repeated API calls within Loop) may cause API usage to exceed the allowed limits.