Auto-sync tags across modules

Sync tags automatically between accounts, related contacts, deals, and cases for consistent tracking and improved reporting in your CRM.

Tags are versatile labels that you can add to accounts, contacts, and other modules in CRM for easier categorization, tracking, and reporting. If you use them extensively, it makes sense to sync them across all the related modules. For example, if you tag an account as a VIP Customer, all associated contacts, deals, and cases should also show that same tag, so that your team instantly recognizes their priority. Adding uniform tags across related modules can also enhance tag-based reporting. For example, if you tag both deals and cases as having a High Churn Risk, you can correlate service issues with lost deals in a single report.

However, a cursory glance at your CRM may reveal that tags are specific to records in a module, and they don't sync with other related modules. Manually re-adding the same tag to an account, contact, deal, or case can quickly become overwhelming and time-consuming. Luckily, there is a way to simplify this process.

You simply need to set up a workflow rule that triggers whenever a checkbox field is selected in an account record. Next, connect this rule to a custom function that automatically transfers all tags assigned to the account to its associated cases, contacts, and deals. You will need to repeat this process for the other three modules to ensure the tags stay in sync. Read on to learn more.

Permissions and availability

  • Users with the Manage Extensibility permission can create connections and write custom functions.
  • Users with the Modules Customization permission can add custom fields.
  • 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 the required scopes for your Zoho CRM account, as detailed in the "Create Connection" section below. Learn more
  • Add a Checkbox field in the Accounts module. Modifying this checkbox field will trigger the workflow rule. Learn more
  • Create a workflow rule for the Accounts module that will trigger a custom function whenever the account's checkbox field is modified. Learn more
  • Write a custom Deluge function that transfers all tags from the account to its associated cases, contacts, and deals. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Create a connection

The first step is to create an OAuth connection in your Zoho CRM account.

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

Add a custom field

The next step is to add a custom checkbox field to the Accounts module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Accounts module to open the layout editor.
  3. Drag and drop the Checkbox field from the New Fields tray to the desired section of the layout.
  4. Name the checkbox field (e.g. "Sync Tags"), define its properties as required.
  5. Once you've finished, select Done, then click Save and Close.

Create a workflow rule

The final step is to add a workflow rule that triggers when the checkbox field is modified.

  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: "Sync account tags to related records".
  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. Choose Specific field(s) gets modified from the drop-down, then enter the condition "When <Sync Tags> is modified to <any value>".
    3. Check the box for Repeat this workflow whenever an Account is edited.
    4. Click Next.
  6. In the Which accounts would you like to apply the rule to? section, select All Accounts, then click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a Name for the function, as well as a description, if necessary.
  9. On the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Choose Accounts - Account Id, name it accountID, and click Save.
    4. Click Save & Execute script.
  10. Click Save on the workflow rule page.

The code

Code Copied
account = zoho.crm.getRecordById("Accounts",accountID);
accountTags = account.get("Tag").toList();
info "accountTags : " + accountTags;
tags_list = List();
for each  accountTag in accountTags
{
	tag1 = Map();
	tag1.put("name",accountTag.get("name"));
	tags_list.add(tag1);
}
info "tags_list : " + tags_list;
relatedCases = zoho.crm.getRelatedRecords("Cases","Accounts",accountID);
if(relatedCases.size() > 0)
{
	recordIDs = List();
	for each  case in relatedCases
	{
		recordIDs.add(case.get("id"));
	}
	info "case recordIDs : " + recordIDs;
	param = Map();
	param.put("tags",tags_list);
	param.put("ids",recordIDs);
	caseTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Cases/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Case Tag : " + caseTag;
}
relatedContacts = zoho.crm.getRelatedRecords("Contacts","Accounts",accountID);
if(relatedContacts.size() > 0)
{
	recordIDs = List();
	for each  contact in relatedContacts
	{
		recordIDs.add(contact.get("id"));
	}
	info "contact recordIDs : " + recordIDs;
	param = Map();
	param.put("tags",tags_list);
	param.put("ids",recordIDs);
	contactTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Contacts/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Contact Tag : " + contactTag;
}
relatedDeals = zoho.crm.getRelatedRecords("Deals","Accounts",accountID);
if(relatedDeals.size() > 0)
{
	recordIDs = List();
	for each  deal in relatedDeals
	{
		recordIDs.add(deal.get("id"));
	}
	info "deal recordIDs : " + recordIDs;
	param = Map();
	param.put("tags",tags_list);
	param.put("ids",recordIDs);
	dealTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Deals/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Deal Tag : " + dealTag;
}

Notes

  • Replace "connectionname" with the name of the connection you specified when creating it (see the "Create a connection" section above).
  • The above script is an example of syncing an account's tags to its related contacts, deals, and cases for consistent tracking and improved reporting in your CRM. You can use this client script code for any other module, such as Contacts or custom modules, by modifying the module name and parameters.
  • You need to repeat this process for the other three modules, such as contacts, deals, and cases, using their respective code snippets listed below to ensure the tags remain in sync between the related module records.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Click the Accounts tab.
  2. Open the account record, which has at least one contact, deal, and case associated with it.
    If necessary, create a new account and associate the related module records.
  3. Select the custom checkbox field and save the action.
    The workflow rule will be triggered.
  4. Check whether the tags from the account record were transferred to the associated contacts, deals, and cases.

Transfer contact tags

Here is the code snippet for transferring tags from contacts to their related accounts, deals, and cases.

Code Copied
contact = zoho.crm.getRecordById("Contacts",contactID);
contactTags = contact.get("Tag").toList();
info "contactTags : " + contactTags;
tags_list = List();
for each  contactTag in contactTags
{
	tag1 = Map();
	tag1.put("name",contactTag.get("name"));
	tags_list.add(tag1);
}
info "tags_list : " + tags_list;
relatedCases = zoho.crm.getRelatedRecords("Cases","Contacts",contactID);
if(relatedCases.size() > 0)
{
	recordIDs = List();
	for each  case in relatedCases
	{
		recordIDs.add(case.get("id"));
	}
	info "case recordIDs : " + recordIDs;
	param = Map();
	param.put("tags",tags_list);
	param.put("ids",recordIDs);
	caseTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Cases/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Case Tag : " + caseTag;
}
relatedDeals = zoho.crm.getRelatedRecords("Deals","Contacts",contactID);
if(relatedDeals.size() > 0)
{
	recordIDs = List();
	for each  deal in relatedDeals
	{
		recordIDs.add(deal.get("id"));
	}
	info "deal recordIDs : " + recordIDs;
	param = Map();
	param.put("tags",tags_list);
	param.put("ids",recordIDs);
	dealTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Deals/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Deal Tag : " + dealTag;
}
if(accountID != null)
{
	param = Map();
	param.put("tags",tags_list);
	recordIDs = List();
	recordIDs.add(accountID);
	param.put("ids",recordIDs);
	accountTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Accounts/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Account Tag : " + accountTag;
}

Transfer deal tags

Here is the code snippet for transferring tags from deals to their related accounts, contacts, and cases.

Code Copied
deal = zoho.crm.getRecordById("Deals",dealID);
dealTags = deal.get("Tag").toList();
info "dealTags : " + dealTags;
tags_list = List();
for each  dealTag in dealTags
{
	tag1 = Map();
	tag1.put("name",dealTag.get("name"));
	tags_list.add(tag1);
}
info "tags_list : " + tags_list;
if(accountID != null)
{
	param = Map();
	param.put("tags",tags_list);
	recordIDs = List();
	recordIDs.add(accountID);
	param.put("ids",recordIDs);
	accountTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Accounts/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Account Tag : " + accountTag;
}
if(contactID != null)
{
	param = Map();
	param.put("tags",tags_list);
	recordIDs = List();
	recordIDs.add(contactID);
	param.put("ids",recordIDs);
	contactTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Contacts/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Contact Tag : " + contactTag;
}
relatedCases = zoho.crm.getRelatedRecords("Cases","Deals",dealID);
if(relatedCases.size() > 0)
{
	recordIDs = List();
	for each  case in relatedCases
	{
		recordIDs.add(case.get("id"));
	}
	info "case recordIDs : " + recordIDs;
	param = Map();
	param.put("tags",tags_list);
	param.put("ids",recordIDs);
	caseTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Cases/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Case Tag : " + caseTag;
}

Transfer case tags

Here is the code snippet for transferring tags from cases to their related accounts, contacts, and deals.

Code Copied
case = zoho.crm.getRecordById("Cases",caseID);
caseTags = case.get("Tag").toList();
info "caseTags : " + caseTags;
tags_list = List();
for each  caseTag in caseTags
{
	tag1 = Map();
	tag1.put("name",caseTag.get("name"));
	tags_list.add(tag1);
}
info "tags_list : " + tags_list;
if(accountID != null)
{
	param = Map();
	param.put("tags",tags_list);
	recordIDs = List();
	recordIDs.add(accountID);
	param.put("ids",recordIDs);
	accountTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Accounts/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Account Tag : " + accountTag;
}
if(contactID != null)
{
	param = Map();
	param.put("tags",tags_list);
	recordIDs = List();
	recordIDs.add(contactID);
	param.put("ids",recordIDs);
	contactTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Contacts/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Contact Tag : " + contactTag;
}
if(dealID != null)
{
	param = Map();
	param.put("tags",tags_list);
	recordIDs = List();
	recordIDs.add(dealID);
	param.put("ids",recordIDs);
	dealTag = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v4/Deals/actions/add_tags"
		type :POST
		parameters:param.toString()
		connection:"connectionname"
	];
	info "Update Deal Tag : " + dealTag;
}

Notes

  • Ensure that you map the CRM variables to their corresponding arguments before saving the function.
  • The solution uses a checkbox field to trigger the workflow and its functions, rather than every time an account and its related modules are edited, to minimize API calls.

Idea

Are you tired of manually selecting and deselecting checkboxes for individual records to sync tags? You can simplify this process by automating the modification of the checkbox field added to the respective modules. All you need to do is create a schedule to check or uncheck the checkbox at a specific time each day. This action will trigger the workflow rule, which will transfer the tags between related modules.

You can use the following code snippet in the schedule:

Code Copied
// Fetch all accounts where you want the checkbox updated
accounts = zoho.crm.getRecords("Accounts",1,200);
// 200 at a time
for each  account in accounts
{
	if(account.get("Sync_Tags") == false)
	{
		bool = true;
	}
	else
	{
		bool = false;
	}
	updateMap = Map();
	updateMap.put("Sync_Tags",bool);
	// Set checkbox ON (true) or OFF (false)
	resp = zoho.crm.updateRecord("Accounts",account.get("id").toLong(),updateMap);
	info "Updated Account ID: " + account.get("id") + " | Response: " + resp;
}

Notes

  • Make sure to use the accurate API names for their corresponding fields (e.g., "Sync Tags") in the code snippet.
  • The code snippet only fetches and updates the first 200 records. If you have more, you must loop through page numbers in a list (e.g., list = {1,2,3,4,5,6,7,8,9,10}) to fetch and update batches of 200 records up to 2000.
  • The script above is an example of how to check or uncheck the checkbox in the accounts module automatically. You can use this code to create a schedule for other modules, such as Contacts and Deals, by modifying the module name and other parameters.

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

ConnectionCustom FieldWorkflow 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!