Add checkbox field names as tags

Automatically add selected checkbox field names of an account as tags in its related contact to segment them based on their account's engagement interests.

Organizing and categorizing contacts is made easier with the use of tags. It enhances contact management and improves efficiency in tracking and engaging with contacts. In addition to the above benefits, you can use tags to add account-related context to their contacts. For example, sales and marketing teams can use tags to segment contacts based on their account's engagement interests. One way to achieve this is by adding the names of selected checkbox fields from an account as tags to its related contact.

All you need to do is write a custom function that automatically adds selected checkbox field names from an account as tags in its related contact. This function can then be connected to a workflow rule that triggers when a contact record is created or edited. 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 the required checkbox fields in the Accounts module. The checkbox fields, when selected, will add the field's name as tags to their related contacts. Learn more
  • Create a workflow rule for the Contacts module that will trigger the custom function whenever a contact is created or edited. Learn more
  • Write a custom Deluge function that adds selected checkbox field names of an account as tags in its related contact and link it up with the workflow rule. 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 creating an OAuth connection in your Zoho CRM account.

  1. Go 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.settings.all
    • ZohoCRM.modules.attachments.all Learn more
  6. Click Create and Connect.
  7. Click Connect and then click Accept to confirm authorization of access for the scopes requested by the client.
Create Connection

Add custom fields

Next, add the custom checkbox fields 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. "Email Opt Out") and define its properties as required.
  5. Add multiple checkbox fields, such as Mobile Opt Out and Newsletter Opt Out.
  6. Once you have finished, click Save and Close.

Create a workflow rule

Next, you must write and connect a custom function with a workflow rule.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Contacts from the module drop-down list.
  3. Provide a name for the rule. For example: "Add account fields as tags". 
  4. Add a description (optional), then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Create or Edit from the dropdown.
    2. Check the box for Repeat this workflow whenever a Contact is edited.
    3. Click Next.
  6. In the Which contacts would you like to apply the rule to? section, select All Contacts, then click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a name and description, if necessary, 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. Choose Contacts - Contact Id, then name it contId.
    4. Click the + icon to add more arguments.
    5. Choose Accounts - Account Id, name it accId.
    6. Click Save, then click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
resp = zoho.crm.getRecordById("Accounts",accId);
tagList = list();
mp = Map();
if(ifnull(resp.get("Email_Opt_Out"),"") == true)
{
	tagList.add("Email Opt Out");
}
if(ifnull(resp.get("Mobile_Opt_Out"),"") == true)
{
	tagList.add("Mobile Opt Out");
}
if(ifnull(resp.get("Newsletter_Opt_Out"),"") == true)
{
	tagList.add("Newsletter Opt Out");
}
info "Tag List :  " + tagList;
for each  ele in tagList
{
	mp = Map();
	mp.put("tag_names",ele);
	response = invokeurl
	[
		url :"https://www.zohoapis.com/crm/v2/Contacts/" + contId + "/actions/add_tags?"
		type :POST
		parameters:mp
		connection:"connection name"
	];
	info response;
}

Notes

  • Replace "connection name" with the name of the connection you specified while creating the connection (see the "Create a connection" section above).
  • With this code snippet, you can add up to three custom checkbox fields as tags. You can add or delete the fields according to your specific requirements.
  • Use the accurate API name of the custom URL field in the code snippet (e.g., "Mobile Opt Out"). Learn more
  • The code above is an example to add selected checkbox field names of an account as tags in its related contact. You can use this code for any other module, such as leads or custom, by modifying the module name and parameters.

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 an account record in which you wish to select the checkbox fields.
  3. On the Account Details page, select one or more of the custom checkbox fields added to the account. For example, Newsletter Opt Out.
  4. Navigate to Contacts and click the Add (+) icon under the Related List menu.
  5. Enter the required contact information, then click Save.
  6. Check whether the new contact was tagged "Newsletter Opt Out" based on the related account's checked field.

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

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