Hello Everyone!
Welcome to unveiling custom functions on our Community series. This week's post lets you add tags to your tickets automatically based on the keywords in the ticket subject and the ticket thread.
Discover how this custom function helps Zylker Techfix, a top gadget service company. Zylker Techfix services many different electronic devices every day, often facing tight deadlines. To make their work easier, they tag tickets based on the content of the email subject or thread for each gadget. This tagging system helps them prioritize cases, allowing Zylker Techfix to maintain a steady pace and provide quick solutions. As a result, their engineers deliver excellent work with less stress, ensuring high customer satisfaction.
Now, this custom function is yours to implement. Follow the steps below to configure it within the workflow rule.
Prerequisites
1. Create a connection
1.1 Go to Setup and choose Connections under Developer Space.
1.2 Click Create Connection.
1.3 Select Zoho OAuth under Default Connection.
1.4 Set the connection name as deskconnection.
1.5 Under Scope, choose the below scope values:
Desk.tickets.Create
Desk.tickets.READ
1.6 Click Create and Connect.
1.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 from the drop-down menu under Module.
4. Enter a Rule Name and Description for the rule.
5. If you want to activate the rule right away, select the Active checkbox. Else, create the rule and activate it later.
6. Click Next.
In the Execute on section, follow these steps:
7. Select Create and Customer Reply.
8. Click Next.
9. Leave the Criteria section blank and click Next.
10. In the Actions section, click the + icon and select New next to Custom Functions.
11. Enter a Name and Description for the custom function.
12. In the script window, insert the Custom Function given below:
- //replace desk domain based on your DC
- deskDomain = "desk.zoho.com";
- //add the required keywords for which tags have to be added
- keywordsList = List();
- keywordsList.add("********");
- ticketTags = list();
- //Enter the Tags to add to the tickets having the above keywords
- ticketTags.add("******");
- //-------------------------------------------
- doesThreadContainRequiredKeywords = false;
- logs = Map();
- latestThreadData = invokeurl
- [
- url :"https://" + deskDomain + "/api/v1/tickets/" + ticketId + "/latestThread?include=plainText"
- type :GET
- connection:"deskconnection"
- ];
- threadContent = latestThreadData.get("plainText");
- logs.put("threadContent",threadContent);
- newContent = threadContent;
- for each currKeyword in keywordsList
- {
- pattern = "(?i).*\b" + currKeyword + "\b.*$";
- if(newContent.matches(pattern) || subject.matches(pattern))
- {
- doesThreadContainRequiredKeywords = true;
- break;
- }
- }
- logs.put("doesThreadContainRequiredKeywords",doesThreadContainRequiredKeywords);
- if(doesThreadContainRequiredKeywords)
- {
- //associate required tag
- ticketTagParams = {"tags":ticketTags};
- associateTag = invokeurl
- [
- url :"https://" + deskDomain + "/api/v1/tickets/" + ticketId + "/associateTag"
- type :POST
- parameters:ticketTagParams.toString()
- connection:"deskconnection"
- ];
- }
- logs.put("associateTag",associateTag);
- info logs;
NOTE
a. In Line 2, Replace ".com" with the domain extension based on your Data Center.
b. In Line 4, Enter the keywords (within " ") that has to be tracked from the ticket subject and ticket thread.
c. In Line 8, Enter the tags names (within " ") to be added to the tickets.
13. Click Edit Arguments and include the argument mapping as below:
13.1 In the Name field, type ticketId and from the Value drop-down list, select Ticket Id under the Tickets Sections.
13.2 In the Name field, type subject, and from the Value drop-down list, select Subject under the Tickets Sections.
14. Click Save to save the custom function.
15. Click Save again to save the workflow.
We hope this custom function helps you sort tickets by automatically associating ticket tags. If you would like to add multiple keywords to a single tag, or other such combinations, please mail to support@zohodesk.com with your use case.
Until next week,
Regards,
Lydia Kiruba | Zoho Desk