Sending Zoho CRM Email Templates Using Zoho Deluge

Sending Zoho CRM Email Templates Using Zoho Deluge

Overview:

Zoho CRM allows users to create Email Templates for sending standardised messages to multiple recipients. In some scenarios, users may wish to send these templates using Deluge through custom functions. This guide outlines the steps to send a Zoho CRM Email Template via Deluge.

Scenario:

Suppose you want to automatically send a Welcome Email Template whenever a new lead is created in Zoho CRM. This can be achieved by creating a Workflow Rule with a Custom Function that triggers the email template.

 

Configuration:

Workflow Rule Setup :

  1. Kindly navigate to setup > Automation > Workflow rules > Create rule.
  2. Select the Leads module and give a name along with the description.
    1. When: Select Record Action >> Create
    2. Condition: All Leads
    3. Instant Actions: Select Function >> Write your own function



Create a Connection:

  1. Navigate to Setup >> Developer Hub >> Connections >> My Connection >> Create Connection
  2. Select "Zoho OAuth" as service and provide Name to "Connection". Then, select the below
    scope:ZohoCRM.templates.email.READ

 

 

 

 

Custom Function Script: 

  1. void automation.Welcomeemail(int leadRecordId)
  2. {
  3. //Associating the template id for the API URL
  4. templateurl = "https://www.zohoapis.com/crm/v2.1/settings/email_templates/"+"6700402000001190011";
  5. templatedata = invokeUrl [
  6. url : templateurl
  7. type : GET
  8. connection : "emailtemplates"
  9. ];
  10. //info templatedata;
  11. // Fetching the content of the respective template
  12. templatecontent = templatedata.get("email_templates").get("0").get("content");
  13. //info templatecontent;
  14. //Since the template has Mergetags such as Lead First name, Last name and Company, fetch such information from the Leads module
  15. Leaddata = zoho.crm.getRecordById("Leads",leadRecordId);
  16. LeadName = ifNull(Leaddata.get("First_Name"),"") + " " + ifNull(Leaddata.get("Last_Name"),"");
  17. Company = ifNull(Leaddata.get("Company"),"");
  18. LeadEmail = ifNull(Leaddata.get("Email"),"");
  19. // Replace the merge tags in Email template with the respective information
  20. revisedcontent = templatecontent.replaceAll("\$\{!Leads.Full_Name\}",LeadName).replaceAll("\$\{!Leads.Company\}",Company);
  21. //info revisedcontent;
  22. //Send the Email to the Lead Email along with the Email template
  23. sendmail
  24. [
  25. from: zoho.adminuserid
  26. to: LeadEmail
  27. subject: "Welcome Email Template"
  28. message: revisedcontent
  29. ]
  30. }

 


NotesNotesIn the API URL, kindly change the domain as per your Data Center. 

Argument Mapping in Deluge RunTime Editor:


Screen Cast Video:





End Result:

 

 

TIPS: Avoid Common Errors

-> Ensure to use the correct API Names for both Module & Fields in the script.


-> To ensure you get the intended output, we would suggest you to use info() logs to each variable to check the output for seamless functionality under the Console section within Zoho CRM Function IDE.


-> Since we have used the Connections within a function script, ensure to have the required scopes added in connection to perform the intended API action. Also, ensure to use the connection link name (i.e., crm_connection ) while passing on to Deluge Invoke URL or Integration Task. 

-> As a common practice, we have used US DC API end point. If you are using CRM account in a different DC (i.e., IN, EU, CA, AU, etc.), then we would recommend you to use the API end point URL according to your DC.

For example:

US DC - "https://www.zohoapis.com/crm/v2/Deals/" + dealRecordID + "/Attachments/" + attachementIdList.get(i)
IN DC - "https://www.zohoapis.in/crm/v2/Deals/" + dealRecordID + "/Attachments/" + attachementIdList.get(i)
EU DC - "https://www.zohoapis.eu/crm/v2/Deals/" + dealRecordID + "/Attachments/" + attachementIdList.get(i)

-> Since the Automation Feature (e.g., Workflow Rules) is involved in this use-case, if the intended functionality does not work, then users can check the associated function failure reason under "Setup >> Developer Hub >> Functions >> Failures". Additionally, Users can also see the complete Log of all function execution for any specific created function to track the executions (i.e. under My Functions >> 3 Dots >> Logs). This also help in a scenario where a function is executed via Workflow rule in CRM record(shows in timeline), however it didn't perform the intended actions/updates in record. In such scenario, users can check the output (info logs) & error of execution via function logs within Zoho CRM.

Notes
Notes: Refer to the following Guide - Article to learn the best practices for Optimizing the code and various ways to deploy Custom Function across Zoho CRM.

  



Quote
Custom Solution Created by Sakthi Priyadharshini | Zoho Partner Support.
If you need any further clarifications, please don’t hesitate to contact partner-support@zohocorp.com.
Notes
Additionally, we kindly ask all "Europe and UK partners" to reach out to partner-support@eu.zohocorp.com.