Blog

How to prepopulate Zendesk custom ticket fields

- Wednesday, July 15, 2015

Zendesk is a great tool for support teams. There is also a very useful feature like custom ticked fields. You can easily add ticket fields and also add their to Zendesk widget. It is possible to use such fields for passing any website visitor specified data to Zendesk. But there is a one problem - Zendesk provide JS API which supports prefill only for two standard fields - Name and Email. It is good of course but not enough. But you can prefill extra fields just with a little hack. jQuery is required for us.

First of all, we need a ticket field ID which can be seen at the top of the corresponding field setup interface.

Well, now if we try to discover Zendesk widget code in your web inspector you can see something like that:


It means that we can insert any data to this field with a very simple JS script (it is an example):

$('#ticketSubmissionForm').contents()
  .find('[name="27253702"]').val("desktop");

 As we see it very easy to prefill the form. But there is  a one problem because Zendesk widget loads through a some time after page loading. A simplest solution is just setting a timeout. Then final code can be looked like that:

function fillZendeskWidgetData(){
  $('#ticketSubmissionForm').contents()
    .find('[name="27253702"]').val("desktop");
}
$(document).ready(function(){
  // Wait 2 seconds after page loading
  setTimeout(fillZendeskWidgetData, 2000);
});

It is a little dirty code and it can be improved but it works. Of course you can also use your template language (like Liquid in Business Catalyst for example) for passing current visitor data.

Oleh Korkh

Get A Free Quote

You will receive quarterly promotions and news. Unsubscribe with one click.

Drop us a line