Using ZRC in Client Script

Using ZRC in Client Script

Hello everyone!

Welcome to another week of Kaizen. In today's post, lets see what is ZRC (Zoho Request Client) and how we can use ZRC methods in Client Script to get inputs from a Salesperson and update the Lead status with a single button click. 

In this Kaizen post,

  1. What is ZRC?
  2.  ZRC Methods
  3. Use Case
  4. Solution
  5. Summary
  6. Related Links

1. What is ZRC?

Zoho Request Client (ZRC) is a built-in SDK in Zoho CRM that provides a unified way to make REST API calls across developer-centric features of Zoho CRM like Client Script, Widgets. Invoking CRM APIs, Connection APIs, and external APIs requires different syntax and separate code for each type. ZRC removes this complexity by offering one common and consistent approach to call all APIs, making client-side development easier and faster.

The following are the key features of ZRC.
  1. ZRC works with any CRM API version
  2. It supports self domain calls by providing only the API endpoint without specifying the domain
  3. Uses a single unified syntax for CRM APIs, custom Connections, and external public APIs. 
  4. No authentication handling needed for the same CRM org as ZRC manages it automatically
  5. Automatic JSON handling without manual parsing.
  6. Supports clean async code with full async-await and promise chaining.

2. ZRC Methods



Click here for more details about ZRC Methods.

3. Use Case - Log call notes and update the Lead status with a button click.

Quote
At Zylker, Salespersons often make multiple call attempts before connecting with a lead. Manually recording these attempts and updating the Lead status is often overlooked, leading to incomplete tracking and inaccurate pipeline data. To address this, the Admin wants the following changes:

1. Display a popup to capture call attempt details when a button is clicked and save them as a Note on the current Lead.

2. Also, update the Lead_Status of the current Lead to “Contacted” .

4. Solution

Here, the requirement is to create a note based on the Salesperson's description and update the status of the Lead record.To achieve this, Salesperson's input is collected through a pop-up when a custom button is clicked. The ZRC POST method is used to create a note for the Lead. The ZRC PUT method is used to update the status of the Lead record. As the Client Script has to be triggered with a button click, you should create a custom button and add Client Script from "Create Custom Button" pop-up.

  1. Go to Setup > Customization > Modules and Fields. Click Leads and navigate to "Buttons" tab.
  2. Specify the details about the custom button, Define action as "Client Script" and click Create.


  1. This opens Client Script IDE.
  2. Enter the following script and click Add in Client Script IDE. 
  1. // Retrieve current Lead module and record ID from the page context
  2. const leadModule = $Page.module;
  3. const leadRecordId = $Page.record_id;
  4. const leadRecordName = $Page.record.Lead_Name || $Page.record.Full_Name || 'Lead Record';
  5. // Dynamically get lead name
  6. // Display a loader to indicate ongoing background operations
  7. ZDK.Client.showLoader({
  8. message: 'Logging call attempt and updating Status'
  9. });
  10. try{
  11. // 1. Create a standardized Note attached to the Lead
  12. var notes_content = ZDK.Client.getInput([{
  13. type: 'text',
  14. label: 'Log Call Details'
  15. },
  16. ], 'Log Call Details', 'OK', 'Cancel');
  17. log(notes_content);
  18. console.log({
  19. notes_content
  20. });
  21. const notePayload = {
  22. data: [{
  23. Note_Title: 'Call Attempt Log',
  24. Note_Content: notes_content[0],
  25. Parent_Id: {
  26. // Associate the note with the current Lead record
  27. id: leadRecordId,
  28. name: leadRecordName,
  29. module: {
  30. api_name: leadModule
  31. }
  32. }
  33. }]
  34. };
  35. const noteCreationResponse = await zrc.post('/crm/v8/Notes', notePayload);
  36. // Check for successful note creation (200 OK or 201 Created)
  37. if(noteCreationResponse.status !== 201 && noteCreationResponse.status !== 200) {
  38. throw new Error('Failed to create Note: ' + JSON.stringify(noteCreationResponse.data));
  39. }
  40. // 2. Update the Lead_Status field to “Contacted” on the current Lead
  41. const leadUpdatePayload = {
  42. data: [{
  43. id: $Page.record_id, 
  44. // Specify the record to update
  45. Status: 'Contacted'
  46. }]
  47. };
  48. const leadUpdateResponse = await zrc.put(`/crm/v8/${leadModule}/${leadRecordId}`, leadUpdatePayload);
  49. $Client.refresh();
  50. // Check for successful lead status update (200 OK or 202 Accepted)
  51. if(leadUpdateResponse.status !== 200 && leadUpdateResponse.status !== 202) {
  52. throw new Error('Failed to update Lead Status: ' + JSON.stringify(leadUpdateResponse.data));
  53. }

  1. In the above script, $Page.module retrieves the current CRM module from which the script is executed.
  2. $Page.record_id fetches the unique ID of the record currently opened on the page.
  3. $Page.record provides access to the field values of the current record.
  4. ZDK.Client.showLoader() displays a visual loading message to inform the Salesperson that background operations are in progress.
  5. ZDK.Client.getInput() prompts the Salesperson to enter details about the call through an input dialog.
  6. ZRC.post() sends a POST request to Zoho CRM to create a new record and automatically handles authentication and domain resolution.
  7. In the notePayload,"Parent_Id" links the created note to the current CRM record and module.
  8. ZRC.put() sends a PUT request to Zoho CRM to update an existing record.
  9. $Client.refresh() refreshes the current CRM page so the latest updates are immediately visible to the Salesperson.
  10. Here is how Client Script works.




5. Summary

1. How to update a record in Zoho CRM using ZRC 
2. How to insert a record using ZRC



    • Sticky Posts

    • Kaizen #226: Using ZRC in Client Script

      Hello everyone! Welcome to another week of Kaizen. In today's post, lets see what is ZRC (Zoho Request Client) and how we can use ZRC methods in Client Script to get inputs from a Salesperson and update the Lead status with a single button click. In this
    • Kaizen #222 - Client Script Support for Notes Related List

      Hello everyone! Welcome to another week of Kaizen. The final Kaizen post of the year 2025 is here! With the new Client Script support for the Notes Related List, you can validate, enrich, and manage notes across modules. In this post, we’ll explore how
    • Kaizen #217 - Actions APIs : Tasks

      Welcome to another week of Kaizen! In last week's post we discussed Email Notifications APIs which act as the link between your Workflow automations and you. We have discussed how Zylker Cloud Services uses Email Notifications API in their custom dashboard.
    • Kaizen #216 - Actions APIs : Email Notifications

      Welcome to another week of Kaizen! For the last three weeks, we have been discussing Zylker's workflows. We successfully updated a dormant workflow, built a new one from the ground up and more. But our work is not finished—these automated processes are
    • Kaizen #152 - Client Script Support for the new Canvas Record Forms

      Hello everyone! Have you ever wanted to trigger actions on click of a canvas button, icon, or text mandatory forms in Create/Edit and Clone Pages? Have you ever wanted to control how elements behave on the new Canvas Record Forms? This can be achieved