How to create workflow rules in Zoho CRM to perform mail merge tasks

How to create workflow rules in Zoho CRM to perform mail merge tasks

Overview

You can automate your Writer's mail merge tasks by creating Workflow rules in your Zoho CRM. Say, for example, you want to automate the merge and send task for every lead entry in your Zoho CRM account (merge every lead entry send an email notification to that lead automatically using workflow rules). The zoho.writer.mergeAndSend task will supply values to the merge fields inserted to a document, and send these merged documents individually to the email ID specified.

Info
You need a Zoho CRM account with manage workflow permission to create a workflow rule and associate it with a custom function.

Steps

Step 1: Create mail merge template in Zoho CRM

Before you get started, create a mail merge template with the required text and graphics. You can create mail merge templates in Zoho Writer and use CRM data (Leads, Accounts, Contacts, and Potentials) to create mail merge documents.
You can also create mail merge templates right inside Zoho CRM. Click here for detailed steps.

Step 2: Create a workflow in Zoho CRM

Workflow Rules in Zoho CRM, are a set of actions including email notifications, and field updates that are executed when specific conditions are met. You can create a workflow rule and set an action to automate Writer's Mail Merge Tasks. (Merge and email, merge and download, merge and store, merge and sign, merge and invoke)
Click here for detailed steps on how to create a workflow rule in Zoho CRM and associate custom function as an instant action.

Once you chose custom function as an instant action, do the following:
  1. You need to write a new custom function in the Deluge script editor and associate with the Workflow rule to automate Writer's mail merge tasks.
  2. Choose "Write your own" option from the Configure Function pop-up. 

  3. In the following Create new function pop-up, enter a function name, display name, and select the module to associate the custom function. Click Next
  4. Now start writing your custom function in the Deluge script editor. Click here to find the steps to programming custom functions in the Deluge script editor.

Step 3: Write your own custom function

You're creating a workflow rule to automate Writer's mail merge tasks including "Merge and Send", "Merge and Download", and "Merge and send for sign". Click here to know more about the available Writer tasks.

Merge and Send

To merge a CRM record data with merge fields and send email automatically.
Syntax
<response> = zoho.writer.v2.mergeAndSend(<document_id>, <merge_detail>, <output_settings>, <optional_settings>, <connection>);
Sample script
A sample script to Merge and send task is shown below:
Quote
// Fetch the CSV data from the web and store it in the variable - csv_content
 csv_content =  invokeurl 
 [
 type : GET
 ];
 
 
 // Construct a KEY-VALUE variable to hold the merge data and subject of the email
 merge_values = Map();
 merge_values.put("subject", "Merge and send Deluge task");
 merge_values.put("merge_data_csv_content", csv_content);
 
 
 // Perform the Merge and Send task 
 response = zoho.writer.mergeAndSend("al296XXXXXXXXXXXXXXXXXXXXXXXXXXXa516c", "inline", "shawn@zylker.com", merge_values, "writer_oauth_connection");

Example
Automatically generate a personalized quote with a CRM record's data and send it as an email. You can even perform multiple actions like storing the generated quote in your desired folder in Zoho WorkDrive and attaching the quote to the CRM record.

Merge and Store

To merge CRM record data and save the merge documents in Writer's folder automatically.
Syntax
<response> = zoho.writer.v2.mergeAndStore(<document_id>, <merge_detail>, <output_settings>, <optional_settings>, <connection>);
Sample Script
A sample script to Merge and Store task is shown below:
Quote
document_id = "po5uobda049e029d4r98r84304jrj32";
                fields = Map(); 
                fields.put("ClientName", "Zylker");
                fields.put("ClientCompany", "Writer");
                fields.put("price", "10000");
                data_map = Map();
                data_map.put("data", fields);
                merge_details = Map();
                merge_details.put("merge_data", data_map);
                optional_settings= Map();
                output_settings = Map();
                output_settings.put("doc_name","SALES PROPOSAL");
                output_settings.put("folder_id","bsa6360a78f53f***");   //Workdrive Folder ID  //optional
                output_settings.put("output_format","pdf");    //docx|pdfform|pdf  //optional
                output_settings.put("password","*****");    //optional
                output_settings.put("overwrite_existing_file","true");    //true|false  //optional
                response = zoho.writer.v2.mergeAndStore(document_id, merge_details, output_settings, optional_settings, "writer_oauth_connection");
                info response;
Example
Generate invoices with a CRM record's data and store it in the desired folder in Zoho WorkDrive. You can even perform multiple actions like sending the invoice via email and marking the status in the CRM record.

Merge and Sign

To merge CRM record data and send the merged document for digital signature collection.
Syntax
<response> = zoho.writer.mergeAndSign(<document_id>, <merge_detail>, <filename>, <signerList>, <option_settings>,  <connection>)
Sample Script
A sample script to perform the Merge and Sign task is shown below:
Quote
document_id = "po5uobda049e029d44b13a9956f6d2cedc67b"; 

fields = Map(); 
fields.put("InvoiceNo","12345"); 
fields.put("InvoiceDate","27 May 2022"); 
fields.put("InvoiceAmount","$100");
data_map = Map();
data_map.put("data", fields)
merge_details = Map();
merge_details.put("merge_data", data_map);

filename = "Invoice data";

signerList = List(); 
signerObj1 = Map(); 
signerObj1.put("recipient_1","john@zylker.com"); 
signerObj1.put("action_type","approve");  //approve|sign|view  
signerObj1.put("language","en"); 
signerObj2 = Map(); 
signerObj2.put("recipient_2","amelia@zylker.com"); 
signerObj2.put("action_type","sign");  //approve|sign|view  
signerObj2.put("language","fr"); 
signerList.add(signerObj1); 
signerList.add(signerObj2);


commonAttachmentFile1 = invokeurl 
type :GET 
]; 


option_settings = Map();

option_settings.put("sign_in_order","true");
option_settings.put("message", "Please find the document to be signed here");   
option_settings.put("set_expire", "30");
option_settings.put("reminder_period", "15");
option_settings.put("common_attachments", commonAttachmentFile1);
option_settings.put("test_mode", "true");

response = zoho.writer.mergeAndSign(document_id, merge_details, filename, signerList, option_settings, "writer_oauth_connection");

info response;
Example
Consider a scenario where a purchase order needs to be signed by multiple people. A sales rep can create a the purchase order with the CRM record's data and send it to sales managers for approval. You can also send the approved purchased order to the client via email.

Merge and Invoke

To merge CRM record data and invoke a custom function or workflow with the merged output.
Syntax
<response> = zoho.writer.mergeAndInvoke(<document_id>, <merge_detail>, <optional_settings>, <connection>)
Sample Script
A sample script to perform the Merge and Invoke task is shown below:
Quote
document_id = "po5uobda049e029d44b13a9956f6d2cedc67b"; 

fields = Map(); 
fields.put("Name", "Ms.Amelia");
fields.put("Tamil", "S");
fields.put("English", "A");
fields.put("Maths", "A");
fields.put("Remark", "Good");
data_map = Map();
data_map.put("data", fields)
merge_details = Map();
merge_details.put("merge_data", data_map);

optional_settings= Map();
optional_settings.put("test_mode", "true");

response = zoho.writer.mergeAndInvoke(document_id, merge_details, optional_settings, "writer_oauth_connection");

info response;

Example
You can merge a deal agreement with your client's details from CRM and send it for signing. And once it is signed, you can invoke a custom function to save a copy of the agreement as an attachment to the CRM record.