Auto-tag a deal for new emails received for its contact

Stay informed of email activity in deals by automatically adding a tag for new emails received for its contact.

To successfully manage deals, it is important to stay on top of any related emails. Effective and timely communication is key to achieving a successful deal outcome. However, if you take a cursory look at your CRM, you may notice that there are no notifications for new emails regarding a deal. Additionally, creating an email workflow automation for incoming emails in the deals module is unavailable. So, how can you stay updated on your deals?

Our low-code tools can come in handy in this scenario. By applying an email workflow rule to contacts and using a custom function, you can easily add a tag to the deal record whenever an email is received. These tags can help you stay informed about email activity related to deals. Continue reading to learn how to accomplish this task in less than 60 minutes.

Permissions and availability

  • Users with the Manage Extensibility permission can create connections and write custom functions.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a Zoho OAuth connection with all the scopes for your Zoho CRM account, as detailed in the "Create Connection" section below. Learn more
  • Create a workflow rule for the Emails module that will trigger a custom function whenever contacts receive an incoming email. Learn more
  • Write a custom Deluge function that adds a tag to a deal based on an email received for its contact. Learn more
  • Test the workflow rule in a sandbox before deploying it in your production environment. Learn more

Create a connection

Follow the below steps to create an OAuth connection in your Zoho CRM account:

  1. Navigate to Setup > Developer Space > Connections.
  2. Click Create Connection.
  3. Select Zoho OAuth under Default Services.
  4. Specify a Connection Name.
    You must enter this name in the code snippet below.
  5. Select the following Scopes to request access.
    • ZohoCRM.modules.all
    • ZohoCRM.modules.attachments.all Learn more 
  6. Click Create and Connect.
  7. Click Connect, then click Accept to confirm authorization of access for the scopes requested by the client.
Create Connection

Create a workflow rule

  1. Navigate to Setup > Workflow Rules > + Create Rule.
  2. Select the Module as Emails from the drop-down list.
  3. Provide a name for the rule. For example: "Add Tag to Deal". 
  4. Add a description, if required, then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Incoming email, then select Received from the drop-down.
    2. Click Next.
  6. In the Which emails would you like to apply the rule to? section, do the following:
    1. Set conditions for email fields if necessary.
    2. In Apply this rule to, choose Contact.
    3. Choose if you want to apply the rule to all contacts or only those matching certain conditions.
    4. Click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a Name and description, if required, for the function.
  9. On the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Enter the name as contId and select the value as Contacts - Contact Id.
    4. Click the + icon to add more arguments.
    5. Enter the name as subject, select the value as Emails - Subject, then click Save.
    6. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
deal_record = zoho.crm.getRelatedRecords("Deals","Contacts",contId);
dealid = deal_record.get(0).get("id").toLong();
//Add properties of incoming emails by mapping respective merge fields
if(subject == "Re: Letter of Quotation")
{
	tag1 = Map();
	tag1.put("name","alert");
	tags_list = List();
	tags_list.add(tag1);
	param = Map();
	param.put("tags",tags_list);
	recordIDs = List();
	recordIDs.add(dealid);
	param.put("ids",recordIDs);
	info param;
	response = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v6/Deals/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "response : " + response;
}

Notes

  • Replace "connectionname" with the name of the connection you specified while creating the connection (see the Create a connection section above).
  • Make sure to use the accurate API names for their corresponding fields in the code snippet. Learn more

Test the solution

  1. Click the Contacts tab.
  2. Open a contact record containing one or more associated deals (see, Related List - Deals).
    If necessary, create and associate a new deal for the contact.
  3. Send an email to the contact's email address using the subject line specified in the custom function (e.g., Re: Letter of Quotation). It is similar to customers replying to a letter of quotation you sent.
  4. See whether the tag "alert" has been added to the deal associated with the contact.

Tip

  • To receive notifications of new incoming emails, you can create a workflow alert that will trigger an email notification whenever the specified tag gets added to a deal record.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleDeals
  • Trigger PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityHigh
  • Implementation Time60 minutes

Features used in the solution

ConnectionWorkflow RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!