Kaizen #67 - Email the contact roles of a deal using Functions

Kaizen #67 - Email the contact roles of a deal using Functions

Happy New Year everyone! We hope you had a wonderful holiday season and are ready to tackle all of the challenges and opportunities that the new year brings.

      In the previous post, we discussed the Contact Roles APIs in Zoho CRM. Today, we will show you how you can send emails to all the contact roles associated with a Deal, using a custom function.

Function to email all contact roles of a Deal

      The Contact Roles related list allows you to link multiple contacts to a single deal and specify their role in the deal. Often you may want to send emails to all the contacts associated with a deal in certain situations. For example, you may want to update all the contacts on the status of the deal, invite all the contacts to a webinar or event related to the deal, or send an important update about the deal. By using a custom function, you can easily send emails to all the contact roles associated with a deal. 

Create and execute the Function

Step 1: Go to Setup > Automation > ActionsFunctions.
Step 2: Click Configure Function.
Step 3: Click Write your own.
Step 4: Enter the following details :
            Function Name 
            Display Name
            Description
            Choose the function category as Leads.
Step 5: Copy and paste the following code in the editor :
 
  relatedcontroles = zoho.crm.getRelatedRecords("Contact_Roles","Deals",input.dealId.toLong());
  salutation = "<p>Hello!!<br /><br /></p>";
  signature = "<br /><br /><p>Best Regards,<br />Patricia Boyle</p>";
  sub = input.emailSubject.toString();
  str = input.emailContent.toString();
  str = concat(salutation,str);
  str = concat(str,signature);
  for each  role in relatedcontroles
  {
emailAddress = role.get("Email");
info emailAddress;
sendmail
[
from :zoho.adminuserid
to :emailAddress
subject :sub
message :str
]
  }


Step 6: Click on Edit Arguments and add the following and then click Save.


Step 7: Click on Save and Execute.
Enter the deal ID, email subject, and content, and click Save to send emails to all the contact roles associated with the corresponding deal. 

Function to Email specific contact roles of a Deal with email template

      There may be times when you want to send emails to only selected contact roles of a deal. For example, when you want to discuss or update the financial aspects of the deal, or if you are discussing the budget for the deal and want to discuss cost-saving benefits, you might want to send emails only to the finance team of the prospective organization. Or, when you are reviewing legal or compliance considerations, or negotiating the terms of the deal, you might want to send an email only to the legal team to discuss these considerations. You can use an email template defined in your account to send the emails instead of drafting the entire content again in the functions.. You can achieve this by using a custom function as well.

Create and execute the Function

Create the connector

Step 1: Go to Setup > Developer Space > Connections.
Step 2: Click Create Connection.
Step 3: Pick the  Zoho OAuth service.
Step 4: Specify the Connection details : Connection Name and Connection Link Name.
Step 5: Choose the following scopes :
ZohoCRM.templates.email.READ
ZohoCRM.modules.All
Step 6: Click Create and Connect and authenticate your connection.

After creating and authenticating your connection, complete the following steps:

Step 1: Go to Setup > Automation > Actions >  Functions.
Step 2: Click Configure Function.
Step 3: Click Write your own.
Step 4: Enter the following details :
            Function Name 
            Display Name
            Description
            Choose the function category as Leads.
Step 5: Copy and paste the following code in the editor :
 
  relatedcontroles = zoho.crm.getRelatedRecords("Contact_Roles","Deals",dealId);
  contactroles = invokeurl
            [
                  url :"https://www.zohoapis.com/crm/v4/Contacts/roles"
                  type :GET
                  connection: "connection_name"
            ];
  roles = contactroles.getJson("contact_roles");
  roles_id = List();
  for each name in roles
  {
role_name = name.getJson("name");
role_id = name.getJson("id");
if(wanted_roles.contains(role_name)){
roles_id.add(role_id);
}
  }
  info roles_id;
  emails = List();
  for each roleid in roles_id
  {
     for each record in relatedcontroles
     {
  if ( record.get("Contact_Role") == roleid ) 
      {
emails.add(record.get("Email"));
      }
    }
  }
  info emails;
  p = contactroles.getJSON("body");
  template = invokeurl
  [
type :GET
connection: "connection_name"
];
  econt = template.getJson("email_templates").toMap().get("content");
  sub = template.getJson("email_templates").toMap().get("subject");
  u = template.getJSON("body");
  for each  email in emails
   {
  sendmail
  [
  from :zoho.adminuserid
  to :email
  subject :sub
  message : econt
  content type :HTML
  ]
  }


Step 7: Replace the connection_name with the name of your connector.
Step 6: Click on Edit Arguments and add the following and then click Save.


Step 7: Click on Save and Execute
Enter the deal ID, the email template ID, and the contact roles you want to send the email to, and click Save to send emails.

We hope you found this post useful. We will be back next week with more interesting topics.
Write to us at support@zohocrm.com if you have any questions, or let us know in the comment section. 

Previous Kaizen Post : Contact Roles APIs

    Access your files securely from anywhere









                          Zoho Developer Community




                                                • Desk Community Learning Series


                                                • Digest


                                                • Functions


                                                • Meetups


                                                • Kbase


                                                • Resources


                                                • Glossary


                                                • Desk Marketplace


                                                • MVP Corner


                                                • Word of the Day


                                                • Ask the Experts



                                                          • Sticky Posts

                                                          • 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
                                                          • Kaizen #142: How to Navigate to Another Page in Zoho CRM using Client Script

                                                            Hello everyone! Welcome back to another exciting Kaizen post. In this post, let us see how you can you navigate to different Pages using Client Script. In this Kaizen post, Need to Navigate to different Pages Client Script ZDKs related to navigation A.
                                                          • Kaizen #210 - Answering your Questions | Event Management System using ZDK CLI

                                                            Hello Everyone, Welcome back to yet another post in the Kaizen Series! As you already may know, for the Kaizen #200 milestone, we asked for your feedback and many of you suggested topics for us to discuss. We have been writing on these topics over the


                                                          Manage your brands on social media



                                                                Zoho TeamInbox Resources



                                                                    Zoho CRM Plus Resources

                                                                      Zoho Books Resources


                                                                        Zoho Subscriptions Resources

                                                                          Zoho Projects Resources


                                                                            Zoho Sprints Resources


                                                                              Qntrl Resources


                                                                                Zoho Creator Resources



                                                                                    Zoho CRM Resources

                                                                                    • CRM Community Learning Series

                                                                                      CRM Community Learning Series


                                                                                    • Kaizen

                                                                                      Kaizen

                                                                                    • Functions

                                                                                      Functions

                                                                                    • Meetups

                                                                                      Meetups

                                                                                    • Kbase

                                                                                      Kbase

                                                                                    • Resources

                                                                                      Resources

                                                                                    • Digest

                                                                                      Digest

                                                                                    • CRM Marketplace

                                                                                      CRM Marketplace

                                                                                    • MVP Corner

                                                                                      MVP Corner







                                                                                        Design. Discuss. Deliver.

                                                                                        Create visually engaging stories with Zoho Show.

                                                                                        Get Started Now


                                                                                          Zoho Show Resources

                                                                                            Zoho Writer

                                                                                            Get Started. Write Away!

                                                                                            Writer is a powerful online word processor, designed for collaborative work.

                                                                                              Zoho CRM コンテンツ






                                                                                                Nederlandse Hulpbronnen


                                                                                                    ご検討中の方







                                                                                                            • Recent Topics

                                                                                                            • Zoho Books Finance Modules Not Accessible in Zoho CRM Mobile App

                                                                                                              We have integrated Zoho CRM with Zoho Books using the Zoho Finance Suite integration. In the CRM web version, we can see the Finance modules (Estimates/Quotes, Invoices, Sales Orders, Items, Payments) and are able to create invoices and quotes directly
                                                                                                            • Zoho CRM Kiosk Upload Files

                                                                                                              Hello all, We are trying out Kiosks at the moment to see where it can fit best in our business. We are still a bit off in the application but lets say we will sort this out. My question is the following - when I create a Kiosk I can add "File Upload"
                                                                                                            • Connecting zoho creator to zoho writer to send prefilled documents

                                                                                                              i will paste the worflow below // Get user's submitted data from the form userSalary = input.Current_Salary; userCIBIL = input.CIBIL_Score; userEmail = input.Email; userName = input.Name; // You need to get the Document ID from the URL of your Zoho Writer
                                                                                                            • Extracting Images from a Zoho Creator Report into a Pages

                                                                                                              If you’ve uploaded images in a form and can see them in your report, you might also want to display those same images inside a Page (custom HTML page). This is useful for dashboards, profile pages, or any place where images should be visible dynamically
                                                                                                            • How do I change a form's name? Why isn't this more intuitive?

                                                                                                              Can someone please let me know how to change a form's name?
                                                                                                            • Zoho is blocking emails I subscribe to from one sender

                                                                                                              About 4 months ago I stopped receiving newsletters that I subscribe to from @thedispatch.com. They tell me that zoho's server is blocking them. I've added them to my contacts list, but they're not even reaching my inbox. I don't know how to troubleshoot
                                                                                                            • Introducing Formula Fields for performing dynamic calculations

                                                                                                              Greetings, With the Formula Field, you can generate numerical calculations using provided functions and available fields, enabling you to derive dynamic data. You can utilize mathematical formulas to populate results based on the provided inputs. This
                                                                                                            • Inactive Items - Make Less Prominent by Default

                                                                                                              Currently, when one marks an Item as "Inactive", it really doesn't do much of anything to hide it or get it out of the way. Search and reporting within Finance should, by default, hide inactive Items from standard reports, searches, etc. If one specifically
                                                                                                            • Items should display under specific warehouse

                                                                                                              I have configured the multi warehouse but it show all the items under all warehouse which is not correct according to our business logic, so i want that items should only display under that specific warehouse not under all the warehouses not even with zero quantity. Some items should be common but not all so is there any option for that purpose so i can specific the items to its warehouse. Regards
                                                                                                            • Zoho Analytics Bulk Api Import json Data

                                                                                                              HI, I’m trying to bulk-update rows in Zoho Analytics, and below are the request and response details. I’d like to understand the required parameters for constructing a bulk API request to import or update data in a table using Deluge. Any guidance on
                                                                                                            • E-Invoicing in Belgium with Zoho Billing

                                                                                                              Starting January 1, 2026, Belgium is introducing mandatory electronic invoices (e-invoicing) for all B2B transactions between VAT-registered businesses. Invoices and credits notes must be exchanged in a prescribed digital format. How E-Invoicing works
                                                                                                            • Convert HTML to PDF & Send as Email Attachments in Zoho Creator (Deluge)

                                                                                                              This approach is useful for sending welcome letters, instructions, or promotional offers after order creation. // 1. Define the variables using the submitted input customerName = input.Customer_Name1; orderID = input.ID; customerEmail = input.Email_Address; //
                                                                                                            • Auto-fill New Row with Previous Row Values

                                                                                                              rowsize = input.Order_Items.count(); for each row1 in input.Order_Items { rowsize = rowsize - 1; if(rowsize == 1) { row.Door_Model = row1.Door_Model; row.Door_Color = row1.Door_Color; row.Materials = row1.Materials;
                                                                                                            • I am facing a problem with an if-else condition

                                                                                                              If I use if, else if, and else conditions in Deluge with the same variable name, sometimes the variable causes an error because the same variable name is present in every block
                                                                                                            • When I click on PDF/PRINT it makes the invoice half size

                                                                                                              When I click PDF / Print for my invoice in Zoho Books, the generated PDF appears at half size — everything is scaled down, including the logo, text, and layout. The content does not fill the page as it should. Could someone advise what causes Zoho Books
                                                                                                            • Python - code studio

                                                                                                              Hi, I see the code studio is "coming soon". We have some files that will require some more complex transformation, is this feature far off? It appears to have been released in Zoho Analytics already
                                                                                                            • API question - adding a thread to an existing ticket

                                                                                                              Hi Is there an API function for the customer to add to an existing ticket thread? example, customer puts in new support ticket. support replies and ask for more details. customer replies with more details -what api function is used for this (will add record append to same ticket number?) Thanks
                                                                                                            • search and Smart Bar both missing in Mail

                                                                                                              One of the users on my account does not have the search bar at the top right or the Smart Bar at the bottom left of the desktop Mail app. Any ideas how to get those back?
                                                                                                            • Why is Zoho Meeting quality so poor?

                                                                                                              I've just moved from Office 365 to Zoho Workplace and have been generally really positive about the new platform -- nicely integrated, nice GUI, good and easy-to-understand control and customisation, and at a reasonable price. However, what is going on
                                                                                                            • Hide fields only for creation

                                                                                                              Hello, I'd like to hide some fields only during the creation of a contact in Zoho CRM. In fact I have some fields that are automatically calculated thanks to an automation, so when my users create a contact I don't want them to fill those fields. I know
                                                                                                            • Items Below Reorder Point Report?

                                                                                                              Is there a way to run a report of Items that are below the Reorder Point? I don't see this as a specific report, nor can I figure out how to customize any of the other stock reports to give me this information. Please tell me I'm missing something s
                                                                                                            • Qwen as the default open source Generative AI model for Zia

                                                                                                              Hello everyone, Zia Generative AI is transitioning from Llama (8B parameters) to Qwen (30B parameters) as the default model. This means that users who were using Llama as a GenAI service will now use Qwen. This upgrade was made with a vision to enhance
                                                                                                            • Calendar week view: Today + 6

                                                                                                              Is there anyway to have the calendar change dynamically based on the date? Due to the amount of events, we only display a week at a time, but towards the end of the week, we can no longer see ahead to next week (without changing it manually every time).
                                                                                                            • How to restrict user/portal user change canvas view

                                                                                                              Hi , I would like to restrict user / portal user change their canvas view because I hide some sensitive field for them. I dont want my user switch the canvas view that do not belong to them But seems Zoho do not provide this setting?
                                                                                                            • E-Invoicing in Belgium with Zoho Books

                                                                                                              Starting January 1, 2026, Belgium is introducing mandatory electronic invoices (e-invoicing) for all B2B transactions between VAT-registered businesses. This means that invoices and credits notes must be exchanged in a prescribed digital format. How E-Invoicing
                                                                                                            • E-Invoicing in Belgium with Zoho Inventory

                                                                                                              Starting January 1, 2026, Belgium is introducing mandatory electronic invoices (e-invoicing) for all B2B transactions between VAT-registered businesses. Invoices and credits notes must be exchanged in a prescribed digital format. How E-Invoicing Works
                                                                                                            • Enhancement Request for Multi-Asset Work Order Feature

                                                                                                              Hello Latha, Thank you for your continued support. The multi-asset Work Order feature is extremely helpful. I did some testing based on our requirements, and during the process, I noticed a few areas where we need your team’s support to improve the feature
                                                                                                            • CRM x WorkDrive: File storage for new CRM signups is now powered by WorkDrive

                                                                                                              Availability Editions: All DCs: All Release plan: Released for new signups in all DCs. It will be enabled for existing users in a phased manner in the upcoming months. Help documentation: Documents in Zoho CRM Manage folders in Documents tab Manage files
                                                                                                            • Weekly Tips : Make collaboration effortless with Whiteboard in Zoho Mail

                                                                                                              Working with your team often means switching between emails, notes, and other applications just to explain an idea. Maybe you are trying to sketch a layout, plan a workflow, or quickly brainstorm ideas—with text alone, things can get confusing. So how
                                                                                                            • Add Option to Mass Dispatch by User

                                                                                                              Hello! We are using the dispatch console to dispatch service appointments to our service ressources. Right now, the process is our dispatcher verifies each ressource's route for the day and dispatches it after validation. Sadly, there doesn't seem to
                                                                                                            • Introducing parent-child ticketing in Zoho Desk [Early access]

                                                                                                              Hello Zoho Desk users! We have introduced the parent-child ticketing system to help customer service teams ensure efficient resolution of issues involving multiple, related tickets. You can now combine repetitive and interconnected tickets into parent-child
                                                                                                            • Error AS101 when adding new email alias

                                                                                                              Hi, I am trying to add apple@(mydomain).com The error AS101 is shown while I try to add the alias.
                                                                                                            • How to add to Subforms via Zapier with Zoho Writer?

                                                                                                              I have the following layout for a Zoho Writer Document. As you can see there is a repeating subform taking in "Items". I am trying to make a Zapier integration with it, and I can see there is 1 field saying: "Items", but it does not specify how I'm supposed
                                                                                                            • Contrôles administratifs granulaires : un atout pour la sécurité des e-mails

                                                                                                              La moindre erreur dans votre système de messagerie peut coûter très cher à votre entreprise, tant en argent qu’en conformité et en image de marque. Pour beaucoup d’organisations, ce risque est bien réel. Les e-mails véhiculent quotidiennement des informations
                                                                                                            • Include the "Added Email ID" to the Filters of a Report

                                                                                                              Hi, With a Report and lots of entries, a normal thing is to filter entries by the submitter, but that is not included in the Auto Filter of Reports and you can't add a custom filter to a Report without specifying the actual value. I would like to be able
                                                                                                            • Marketer's Space: Why mobile optimization deserves a place in your email strategy

                                                                                                              Hello Marketers, Welcome back to Marketer's Space! Today, we'll talk about the importance of creating mobile-friendly email designs. While mobile phones were once used only to make phone calls, today they're used for almost everything, including texting,
                                                                                                            • Collections Management: #6 Realign Customers who gets back In-Term

                                                                                                              Arun stared at the subscription list on his dashboard. Another account had just been moved to Cancelled status after completing the whole dunning process. Nothing unusual, just that payment failures happen, retries fail, and cancellation is the expected
                                                                                                            • Zoho Mail IP Blacklist

                                                                                                              I need problems with send mails: Error: junk mail rejected - sender4-op-o10.zoho.com 136.143.188.10, is in RBL. Spamcop. Please remove FQDN for blacklist. Regards.
                                                                                                            • I can receive but not send emails

                                                                                                              Hello, I've been not able to send emails for almost a year now. I been using alternate email to do this. I want to know how to fix this so I can use my zoho account normally again.
                                                                                                            • Setting checkbox value on template in Sign from Creator

                                                                                                              Good day, Please help me understand how do I set a tick from a checkbox in Creator into a checkbox on a Sign template. Below is the only values on the Sign template and the code from Creator, "field_boolean_data": {}, "field_date_data": {}, "field_radio_data":
                                                                                                            • Next Page