Rockel is a top-tier client of Zylker traders. Marcus handles communications with Rockel and would like to add Terence, the CTO of Zylker traders to the email conversations. In this case, the emails coming from user address rockel.com should have Terence looped in automatically as the secondary contact.
Like Zylker, many users have the requirement to include secondary contacts while communicating with their customers. Here's for you the custom function to automatically add static secondary contacts while responding to an email.
Prerequisite
1. Enable Secondary Contacts (CCs) in Tickets.
Navigate to Setup >> Customization >> General Settings >> Tickets >> Secondary Contacts (CCs) in Tickets >> Configure(If not enabled) or Edit Configuration(If enabled), select the department to which you want to implement the automation.
2. Create a Connection
To establish a connection, perform the following steps:
2.1 Go to Setup and choose Connections under Developer Space.
2.2 Click Create Connection.
2.3 Select Zoho OAuth under Default Connection.
2.4 Give the connection name as secondarycontact.
2.5 Under Scope choose the below scope values:
Desk.search.READ
Desk.tickets.READ
Desk.tickets.UPDATE
Desk.contacts.READ
Desk.contacts.UPDATE
2.6 Click Create and Connect.
2.7 Click Connect and click Accept.
Connection is created successfully.
Create a Workflow Rule
1. Go to Setup, choose Workflows under Automation.
2. Under Workflows, click Rules >> Create Rule.
In the Basic Information section
3. Select Tickets under Module.
4. Enter a Rule Name and Description for the rule.
5. To activate the rule, select the Active checkbox. Click Next.
In the Execute on section, follow these steps:
6. Select Create checkbox to execute this rule every time a new ticket is created. Click Next.
7. In the Criteria section, specify the criteria as "Email contains @zylker.com" and click Next.
8. In the Actions section, click the + icon and select New next to Custom Functions.
9. Enter a name and description for the custom function.
10. In the script window, insert the Custom Function given below:
- //--------------- User Input -----------------
- Email = "STATIC_EMAIL_ID"; // Static email ID
- deskURL = "https://desk.zoho.com";
- //-----------------------------------------------
- logs = Collection();
- secondaryContacts = list();
- ticketDetails = zoho.desk.getRecordById(orgId, "tickets", ticketId, "secondarycontact");
- logs.insert("ticketDetails": ticketDetails);
- secondaryCC = ticketDetails.get("secondaryContacts");
- if (secondaryCC != "" && secondaryCC != null)
- {
- secondaryContacts = secondaryCC.toList(",");
- }
- searchParam = Map();
- searchParam.put("from", 0);
- searchParam.put("limit", 1);
- field1 = "email:" + Email;
- encryptEmail = zoho.encryption.urlEncode(field1);
- searchParam.put("field1", encryptEmail);
- contactSearch = invokeurl
- [
- url: deskURL + "/api/v1/contacts/fieldSearch"
- type: GET
- parameters: searchParam
- connection: "secondarycontact"
- ];
- logs.insert("contactSearch": contactSearch);
- if(contactSearch != null && contactSearch.get("data") != null && contactSearch.get("data").size() > 0)
- {
- contactId = contactSearch.get("data").get(0).get("id");
- }
- else
- {
- createConatctParam = Map();
- lastName = Email.getPrefixIgnoreCase("@");
- createConatctParam.put("lastName", lastName);
- createConatctParam.put("email", Email);
- createContact = invokeurl
- [
- url: deskURL + "/api/v1/contacts"
- type: POST
- parameters: createConatctParam.toString()
- connection: "secondarycontact"
- ];
- logs.insert("createContact": createContact);
- contactId = createContact.get("id");
- }
- logs.insert("contactId": contactId);
- if(contactId != null && contactId != ticketContactId)
- {
- secondaryContacts.add(contactId);
- updateParam = Map();
- updateParam.put("secondaryContacts", secondaryContacts);
- updateTicket = invokeurl
- [
- url: deskURL + "/api/v1/tickets/" + ticketId
- type: PATCH
- parameters: updateParam.toString()
- connection: "secondarycontact"
- ];
- logs.insert("updateTicket": updateTicket);
- }
- info logs ;
![](https://static.zohocdn.com/zoho-desk-editor/static/images/file.png)
Note: In Line 1 Email = "STATIC_EMAIL_ID", replace the "STATIC_EMAIL_ID" with the email address you prefer to be added in the secondary contact automatically. eg: Email = "terence@zylker.com" 11. Click Edit Arguments and include the argument mapping as below:
11.1 In the Name field type ticketId, and from the Value drop-down list select Ticket Id under Ticket Information.
11.2 In the Name field type ticketContactId, and from the Value drop-down list select Contact Id under Contacts Information.
11.3 In the Name field type orgId, and from the Value drop-down list select specify custom value and enter your Zoho Desk. OrgId. To get Zoho Desk OrgId, navigate to Setup >> Developer Space >> API.
12. Click Save to save the custom function
13. Click Save again to save the workflow.
We hope this custom function fosters your experience with Zoho Desk. Stay tuned for regular updates and insights on our automation features in this space.