Transfer tags from accounts to their related contacts

Automatically transfer tags from an account to its related contacts while adding them to the account record.

If you often use tags to categorize customer accounts in your CRM, transferring those tags to their corresponding contacts can simplify your customer database management. By transferring tags from an account to its contacts, you can easily access their requirements, preferences and other tag attributes without having to look into their account record. However, how could you do it without manually adding them to the contacts? Well, it's just a function away.

Using functions, you can automatically transfer tags from an account to its contacts while adding them to the account record. You just need to create a custom function and connect it to a workflow rule for the Accounts module.

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 Accounts module that will trigger a custom function whenever an account is edited. Learn more
  • Write a custom Deluge function that transfers tags from an account to its related contacts. Learn more
  • Test the workflow rule in a sandbox before deploying it in your production environment. Learn more

Create a connection

The first step is 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

The next step is to create a workflow rule linked to a custom function.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select the Module as Accounts from the drop-down list.
  3. Provide a name for the rule. For example: "Transfer Tags". 
  4. Add a description, if required, then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Edit from the drop-down.
    2. Check the box for Repeat this workflow whenever an Account is edited.
    3. Select Specific field(s) get modified and specify "When <Tag> is modified to <any value>".
    4. Click Next.
  6. In the Which accounts would you like to apply the rule to? section, select All Accounts and 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 acctId and select the value as Accounts - Account Id.
    4. Click Save.
  10. Click Save on the workflow rule page.

The code

Code Copied
acctinfo = zoho.crm.getRecordById("Accounts",acctId);
tagname = "";
tagvalue = ifnull(acctinfo.get("Tag"),"");
if(tagvalue != "")
{
for each ele in tagvalue
{
tagname = tagname + ele.get("name") + ",";
}
}
newtagname = tagname.removeLastOccurence(",").trim();
mp = Map();
mp.put("tag_names",newtagname);

relatedContacts = zoho.crm.getRelatedRecords("Contacts", "Accounts", acctId);
if(relatedContacts.size()>0)
{
	for each contact in relatedContacts
	{
		contId = contact.get("id"); 

		response = invokeurl
		[
		url :"https://www.zohoapis.com/crm/v2/Contacts/" + contId + "/actions/add_tags?"
		type :POST
		parameters:mp
		connection: "connectionname"
		];
		info 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 Accounts tab.
  2. Open an account record that contains one or more contacts associated with it (see: Related List - Contacts).
    If necessary, create and associate a new contact for the account.
  3. Add a new tag to the account record and click Save.
  4. Check whether the account's tag value gets transferred to all of its associated contacts.

Tip

  • You can transfer tags from leads to accounts, contacts, and deals during individual or bulk conversion. Learn more

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

  • ModuleAccounts
  • 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!