How to prepopulate Zendesk custom ticket fields

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.

Blog ticket field

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

Zendesk field attribute

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


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(){
  // 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.