Auto-populating fields in ticket forms with custom field input data | Community
Skip to main content

Auto-populating fields in ticket forms with custom field input data

  • August 23, 2019
  • 4 replies
  • 0 views

We're very close to where I need to be with customizing one of our ticket forms. We hide the Subject and Description and we're able to assign static values for them but we're looking to populate the fields with actual data being submitted in the form. Here is the code we are using:

var ticketForm = location.search.split('ticket_form_id=')[1];

var subject_value = "New Email Request for " + $("request_custom_fields_1111111").val();

if(ticketForm == 2222222) {

$('#request_subject').val(subject_value);

$('#request_description').val(subject_value);

$('#request_subject').parent('.request_subject').hide();

$('#request_description').parent('.request_description').hide();

};


When I submit the form with that code, the subject and description just say "New Email Request for " and does not include the custom field data which is part of the form being submitted. I've tried different variations from what I've seen online to include single quotes, input# and even brackets and sometimes I get "New Email Request for undefined" or "New Email Request for [object Object]".

Any help in solving this is greatly appreciated. Thank you.

4 replies

Brett13
  • Community Manager
  • August 29, 2019

Hey R. Bello,

While I can't assist with custom code on my end, I did want to share some documentation we have available that may help point you in the right direction:

I'll also get this post added to our Community Roundup for August to help provide visibility to other users who may be able to offer up some guidance. 

Cheers!


  • Author
  • September 5, 2019

Zendesk Support provided a link to this post:

https://support.zendesk.com/hc/en-us/community/posts/208167958-Hiding-attachment-system-fields-on-ticket-form

and I was able to find the right code for it. It wasn't coded under $(document).ready(function(), it had to include a submit function, see below:

 

$(document).submit(function() {

var subjectstring1 = $("#request_custom_fields_1111111111").val();

if (window.location.href == "https://subdomain.zendesk.com/hc/en-us/requests/new?ticket_form_id=222222222"){
$('#request_subject').val("New Email" + " - " + subjectstring1);

 


  • November 22, 2020

Can you remove subject and body/description for a single brand among several?


  • November 23, 2020

Hi Daniel,

In the request form you could do that yes.
Something like

if (window.location.href.indexOf("BRAND URL HERE") > -1) {
document.querySelector('.request_subject').style.display = "none";
document.querySelector('.request_description').style.display = "none";

document.querySelector('.request_description').style.display = "none";
}