Skip to content

Instantly share code, notes, and snippets.

@skipjac
Created June 2, 2011 06:06
Show Gist options
  • Select an option

  • Save skipjac/1004006 to your computer and use it in GitHub Desktop.

Select an option

Save skipjac/1004006 to your computer and use it in GitHub Desktop.
Replace Zendesk ticket type with a custom field. It also sets the system ticket type in the background
//Replaces the Zendesk system ticket type with a custom field.
$j(document).ready(function() {
//the custom field ID
var customfield = "20111118";
//check to see if you are on the agent ticket page
if(window.location.href.indexOf('tickets') >= 0) {
//hide the custom field label and the system ticket type
$j('select#ticket_fields_'+ customfield).prev().toggle();
$j('select#ticket_ticket_type_id').toggle();
//Get the current selection of the custom field
var userSelection = $j('select#ticket_fields_'+ customfield +' option:selected').text();
//If the selection is Task how the Date field
if(userSelection ==! 'Task') { $j('#ticket_date.select').hide(); }
//If the selection is a Incident show the problem drop down field
if(userSelection ==! 'Incident') { $j('#ticket_link.select').hide(); }
//place the custom field where the system ticket ID field was
$j('#ticket_ticket_type_id').after($j('select#ticket_fields_'+ customfield));
//monitor the dropdown field
$j('select#ticket_fields_'+ customfield).change(function(endUserselect){
//grab the value of the dropdown
userSelection = $j('select#ticket_fields_'+ customfield +' option:selected').text();
//show and hide the correct fields. Also set the ticke type ID in the background
if(userSelection === 'Task'){
$j('#ticket_link.select').hide();
$j('#ticket_date.select').toggle();
$j('select#ticket_ticket_type_id').val('4');
}
//hide them again if the user changes his mind
else if (userSelection === 'Story') {
$j('#ticket_date.select').hide();
$j('#ticket_link.select').hide();
$j('select#ticket_ticket_type_id').val('1');
}
else if (userSelection === 'Epic') {
$j('#ticket_date.select').hide();
$j('#ticket_link.select').hide()
$j('select#ticket_ticket_type_id').val('1');
}
else if (userSelection === 'Question') {
$j('#ticket_date.select').hide();
$j('#ticket_link.select').hide();
$j('select#ticket_ticket_type_id').val('1');
}
else if (userSelection === 'Problem') {
$j('#ticket_date.select').hide();
$j('#ticket_link.select').hide();
$j('select#ticket_ticket_type_id').val('3');
}
else if(userSelection === 'Incident') {
$j('#ticket_date.select').hide();
$j('#ticket_link.select').toggle();
$j('select#ticket_ticket_type_id').val('2');
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment