Skip to main content


This is a Freshplug. Perhaps someone has a use for it.






One of our teams requested that the ticket subject is automatically modified to include the value of a ticket field called 'Project Number'. In this way it is easier for them and for customers to keep track of projects and also makes searching for projects ( including using the Freshdesk search tool ) more efficient.






For this to work, you must first create a 'Number' type custom ticket field named 'Project Number' by navigating to Admin > Ticket Fields. This can be either an independent, top-level field or a a field under some hierarchical menu ( in our case it is under a specific ticket 'Type' ).






The freshplug works by checking the value of that 'Project Number' field, in the ticket page, when the sidebar has loaded and when the ticket fields

are updated. It starts by assembling the 'proper' subject ( ie remove all semblances of a project number from the current subject and then prepend the project number, in the form 'PROJ.xxx - ' if the 'Project Number' field is not empty ). Then it compares the 'proper' subject to the current one and if they are different, replaces the current subject with the 'proper' one ( both on page and in the database ). As mentioned, searching for 'PROJ.xxx' is very efficient.






Once you create the 'Project Number' field you will find it in the HTML source of ticket pages as:






<input class="  number" id="helpdesk_ticket_custom_field_project_number_359268" ...






Please note the number, highlighted above, that applies to your Freshdesk installation as it is the one thing you must edit in the source code bellow.






The code for the freshplug is:



 



<div id="change_subject"></div>

<script type="text/javascript">

(function($) {

var ModifySubject = Class.create();

ModifySubject.prototype = {

initialize: function() {},

ticketAjaxCallPutCurrent: function(json_data) {

var this_object = this;

jQuery.ajax({

type: 'PUT',

url: '/helpdesk/tickets/{{ticket.id}}.json',

contentType: 'application/json',

dataType: 'json',

data: json_data,

success: function(data) {

jQuery('h2.subject').html(proper_subject);

document.title = ' #{{ticket.id}}] ' + proper_subject;

}

});

}

}



var modify_subject = new ModifySubject();

var value_custom_field_project_number = '';

var current_subject = '';

var proper_subject = '';



jQuery(document).ready(function() {

jQuery('#change_subject').closest('.widget').removeClass('widget');

});



jQuery(document).on('sidebar_loaded ticket_fields_updated', function() {

current_subject = '{{ticket.subject}}';

proper_subject = current_subject.trim();

value_custom_field_project_number = jQuery('#helpdesk_ticket_custom_field_project_number_359268').val();

proper_subject = proper_subject.replace(/(^|\s+)PROJ\.\0-9]+\s+\-\s+/g, ' ');

if (value_custom_field_project_number) {

proper_subject = 'PROJ.' + value_custom_field_project_number + ' - ' + proper_subject;

}

proper_subject = proper_subject.replace(/\s{2,}/g, ' ');

if (proper_subject != current_subject) {

//console.log('(' + proper_subject + '] != =' + current_subject + ']');

modify_subject.ticketAjaxCallPutCurrent('{ "helpdesk_ticket" : { "subject" : "' + proper_subject + '"}}');

}

});



})(jQuery);

</script>


 



First replace the number '359268' with what applies for your Freshdesk installation.






Then save this code as a new Freshplug by navigating to Admin > Apps >  Custom Apps > New Custom app ( if your installation supports Freshplugs ). Select Custom app displayed on Ticket detail page ( the default ) then Save and you should be done.









Actually, if you replace 359268 with the string {{account_id}} the code will work. There is no need for you to find your Account ID.

 




We had not made "Subject" a required field on our tickets from the customer portal.  Would your solution work to get a custom field (in our case Reference Number) added to a ticket that doesn't already have a subject?




I doubt that you can use my Freshplug because Freshdesk has switched to a different method of injecting custom code ( SDK + Marketplace ). Perhaps you could port it but I don't know how easy this could be. Also, you might have to rewrite pieces of the code if you use the newer Mint UI.