Auto-Populating Custom Ticket Fields based on Tags (Zendesk Classic)

Our company wants to separate tickets based on online data vs phone data.  This represents a  logical boolean value for us:  'phone' or 'online' ticket.

In other words, if the source of the ticket is some kind of phone interaction then certain Triggers detect that information within the ticket, (when the ticket is first created),  and the Triggers create tags such as 'vm' for voice mail, 'phone_interaction' for direct calls, and 'fax' for faxes.   For reporting purposes, these 3 tags, 'vm', 'phone_interaction', and/or 'fax' determine that the ticket is logically a "phone" ticket.  Otherwise, if the ticket does not have one of those tags, it is considered logically an 'online' ticket, which originates from some time of Web interaction.

We integrate with GoodData, and Tags represent a "many-to-many" relationship in GoodData, which makes it very difficult to break reports into Tag categories.  The direct 1-to-1 relationship between a particular ticket and the Tag(s) for that ticket gets broken when writing complex metrics in GoodData.  We need to retain a 'one-to-one" relationship between the Tag data for each individual ticket.  So, we came up with a solution of creating a custom ticket field in Zendesk that would basically act like a boolean field.  Here is the complete solution, and you can customize this solution to your particular requirements:

First, I created a custom ticket field called "Source" which is a simple integer field.  It is not required and it is not visible.  It is auto-populated based on the Tags on that ticket.  The Global Javascript Widget code only runs when someone clicks on the ticket.  That is the only limitation to the code.  But there really wouldn't be any reason to solve/close a ticket without interacting with the ticket first.  So every ticket, theoretically, should have the Source value populated.

The ticket Tags are created by Triggers , based on information contained within the ticket when it is first created, so the Tag information that we are looking for is already there before anyone interacts with the ticket, IE., the Javascript won't run prior to the Tag being created.

The logic is this:  If there is a ticket Tag that is either 'vm' or 'phone_interaction' or 'fax' then we know that ticket was created via some type of phone interaction.  Otherwise, we know the ticket was created online via some web interface.  So, the value of '0' for the "Source" ticket field is the default value and will be an indication of an email ticket.  Whereas a value of '1' is assigned to the "Source" ticket field if one of those 3 ticket tags exist.  And here is the "Global Javascript Widget" code that a genius Web Developer here helped me to write.   (Note:  The actual Ticket field numbers would change depending on the actual ID of the custom ticket field you create.)


var tktIsPhone = 0;
var tktTagValue = $j("#ticket_tags ").val();
if ( tktTagValue.match(/(fax|vm|phone_interaction)/) != null) {

tktIsPhone = 1;


1 comment

Please sign in to leave a comment.
Help them find what they're looking for
Create an online destination for 24/7 support with Zendesk