Requirement Overview
A Zoho CRM user wants to automate and simplify the process of sending a repetitive emails to different customers based on user's specific action, instead of manual clicking on Send Email button each time.
Use-case
In a Product Based Company, the sales team regularly engages with potential clients via email after initial discussions. Depending on the deal stage (Won, Lost, or On-Hold), the sales representative needs to send tailored communication:
Deal Won → Send a thank you email with onboarding details.
Deal Lost → Send a polite follow-up or feedback request email.
Deal On-Hold → Send a nurturing email to keep the client engaged.
It is very important for sales representative to communicate as soon as possible to complete the deal effectively. Hence, Company wants a automated process of sending emails based on every deal stage/status. Company also needs to verify the email everytime before it get sends to customer.
Possible ways to achieve it within Zoho CRM
=> User can use Workflow directly based on record edit trigger and set an action to send Email Notification effectively. However, users cannot verify the email which will be sent to customer before it get sent. Also, we cannot have a dynamic content in this approach.
=> User can use Custom Function with Send Mail action and dynamic content by associating it as action within Workflow. However, emails will be sent automatically and it cannot be verified by users before it get sent.
=> Client Script provides a default ZDK method - 'openMailer()' which will be used to invoke the mail composer within a record with predefined configuration.
Refer to following
Help Link to know more about
openMailer() method in Client Script.
Why It is Important:
- Time-Saving
- Consistency
- Personalization
- Error-Free
- Improves both User & Customer Experience
- Sales Productivity
- Speed up internal process of Business
Permissions & Availability
-> Users with the Manage Extensibility can configure & setup Client Script.
-> Users with the Manage Sandbox permission can manage the sandbox and test this use-case.
Configuration
To have a simple understanding on above explained use-case, we will explore how a client script will be triggered based on each status of a field and open Mailer composer with predefined information.
Now, let us create a Client Script on Detail Page of a 'Sales Order' Module for a Field Event with onBeforeUpdate() (i.e. Status). As an example, whenever the user updates 'Status' to any option in Detail Page, script will be triggered and open mailer composer with specified configuration.
Follow the steps below to configure the Client Script for this use case:
1) Provide the basic information, like Name and Description based on script purpose.
2) In the Category Details section, please choose the following:
* Category as Module.
* Page as Detail.
* Module as Sales Order.
* Choose the required Layout.
3) In the Event Details section, please choose the following:
* Type as a Field Event.
* Choose the required Field from the drop-down.
* Event as onBeforeUpdate.
The Code
- //fetching Status field value
- var status = value;
- //checking if status value is 'Approved'
- if (status == 'Approved') {
- //opening Mailer Component
- ZDK.Client.openMailer({
- from: 'harshadjoshi518@gmail.com', to: [{ email: 'harshikajoshi51@gmail.com' }], subject: 'Order Confirmation', body: 'This is to inform you that your order has been approved. Please confirm if you would like to confirm the order' });
- }
- //checking is status value is 'Confirmed'
- if (status == 'Confirmed') {
- //showing confirmation popup in UI
- var resp = ZDK.Client.showConfirmation('Are you sure, you want to confirm the order?', 'Yes!', 'Nope!');
- //if Yes selected by user, then proceed futher
- if (resp == true) {
- templateId = "5113649000017098722";
- recid = $Page.record_id;
- //fetching template data using templateID by invoking CRM_API using Connection Method
- var fetchRec = ZDK.Apps.CRM.Connections.invoke("zohocrm", "https://www.zohoapis.com/crm/v4/settings/email_templates/" + templateId + "/actions/print_preview?record_id=" + recid + "&print_type=html", "GET", 1, {}, {});
- content = fetchRec.details.statusMessage.email_template_preview.body;
- console.log(content);
- //opening Mailer Component
- ZDK.Client.openMailer({ from: $Crm.user.email, to: [{ email: '123@1213.com', label: 'Test' }], cc: [], subject: "Hello", body: content });
- }
- }
-> Initially, we will fetch the respective Status field value (due to which the client script triggered).
-> Then, we use IF condition to have different email compose based on each status.
-> As an example, we used direct email body content to "Approved" status.
-> For "Confirmed" status, we are showing up a Confirmation Pop-up and if user clicks on "Yes", then we fetch the required template by ID using default Web API method (i.e., Connections) to get the template content.
-> Then, we use the Mailer Component to open it automatically by passing the template content as the body.
Working Demo - Screencast
-> User can configure the same setup for above explained Use-Case related to Deal Stages for Sales Team.
Different Use-case:
-> A School, where administrator want to send email to all related guardian of student.
-> Here, users can fetch all guardian records (associated via related list using CRM API) and get the email addresses, then pass it onto Mailer Component (To Address - parameter) to send email all guadians.