Welcome back everyone!
Business scenario:
The Deals module in Zoho CRM is designed to associate only one Contact per deal. Very often, B2B sales require touching upon multiple stakeholders, and the person you engage with need not be the decision maker. It is essential to keep track of all the contacts related to a deal. The Contact Roles field, listed under the Related List in deals module helps you do just that. It lets you profile multiple buyers associated with the deal based on their level of influence - Decision maker, Evaluator, Executive Sponsor, etc.
Part of the process while dealing with multiple buyers is sending updates on deal progression. The Executive Sponsor might be interested in the Price Quote. The evaluator might be interested to know whether deal is won. What if you want to update all the buyer profiles listed in the Contact Roles on deal progression. Getting all the email addresses from CRM and sending an email from your email client is indeed laborious. This week's custom function helps you automate this requirement by sending emails to all the related contacts about deal progress in a jiffy. However, as this custom function links to workflow with a canned message related to the deal status, it is required to replicate this multiple times based on the deal stages that require email notification. The required steps are detailed below:
Getting started with the custom function:
- Go to Setup > Automation > Actions > Custom Functions > Configure Custom Function > Write your own.
- Provide a name for the button. For example: “Send updates on deals to clients”. Add a description(optional).
- Choose the module as "Deals".
- Click “Free flow scripting”.
- Copy the code given below.
- Click “Edit arguments”.
- Enter the name as “potId” and select the value as “Potential Id”.
- Save the changes.
- Click Save to create the button.
The script:
Code for Version 2.0 API:
relatedcontroles = zoho.crm.getRelatedRecords("Contact_Roles", "Deals", input.dealId.toLong());
//info relatedcontroles;
potIdStr=input.potId.toString();
potentialDetails = zoho.crm.getRecordById("Deals",input.dealId);
name=ifnull(potentialDetails.get("Deal_Name"),"");
closedate=ifnull(potentialDetails.get("Closing_Date"),"");
closetime=ifnull(potentialDetails.get("Closing _ime"),"5:00");
closelocation=ifnull(potentialDetails.get("Closing_Location"),"chennai");
for each role in relatedcontroles
{
emailAddress= role.get("Email");
info emailAddress;
str="<p>Hello all,<br /><br />Just wanted to make sure everyone hear the great news... the closing for " + name + " has been scheduled.<br />Date: " + closedate + " <br />Time: " + closetime + "<br />Location: " + closelocation + "<br /><br />Sincerely,<br />Gregory Pfeiffer .</p>";
sendmail
[
from:zoho.adminuserid
to:emailAddress
subject:"Closing Scheduled"
message:str
content type:HTML
]
}
Code for Version 1.0 API:
auth="xxxxxxxxxxxxxxxxxxxxx";
potIdStr=input.potId.toString();
potentialDetails = zoho.crm.getRecordById("Potentials",input.potId);
name=ifnull(potentialDetails.get("Potential Name"),"");
closedate=ifnull(potentialDetails.get("Closing Date"),"");
closetime=ifnull(potentialDetails.get("Closing Time"),"5:00");
closelocation=ifnull(potentialDetails.get("Closing Location"),"chennai");
info test;
data=test.get("responseText");
email = data.executeXPath("/response/result/ContactRoles/row/FL[@val = 'Email']/text()");
emailids=email.toList("-|-");
for each email in emailids
{
emailAddress=email;
info emailAddress;
str="<p>Hello all,<br /><br />Just wanted to make sure everyone hear the great news... the closing for " + name + " has been scheduled.<br />Date: " + closedate + " <br />Time: " + closetime + "<br />Location: " + closelocation + "<br /><br />Sincerely,<br />Gregory Pfeiffer .</p>";
sendmail
[
from:zoho.adminuserid
to:emailAddress
subject:"Closing Scheduled"
message:str
content type:HTML
]
}
Note:
- The above code is written to update on closed deals. You may change the parameters 'closedate, closetime and closelocation', subject and the content of the email to customize it for other deal stages.
- Change the 'xxxxxxxxxxxxxxxxxxxxx' in the authtoken with your own.
Found this useful? Try it out and let me know how it works! If you have questions, do not hesitate to ask! Share this with your team if you find it useful.
Do check out other custom functions shared in this series here.
See you all next week with another interesting custom function. Ciao!
Update: As you must be aware, API V1.0 will be deprecated and support for version 1.0 API will be available only till Dec 31, 2018. Version 1.0 compatible Functions will continue to work until Dec 31, 2019. You're advised to migrated to API Version 2.0 at the earliest. Check this announcement for more. We've updated the post to include the Version 2.0 compatible Function.