Recent searches
No recent searches
Automatically Populate Subject and Description Based on Drop-Down
Posted Jun 05, 2017
Utilizing a custom JS listener on the "New Request Page" I want to listen for my "custom field" and set the subject and description based on the selection. I think I can access this based on the following code and a case or select statement; can anyone tell me if i'm on the correct path.
custom_field_75567587.addEventListener('change', function() {
switch (custom_field_75567587.value){
case conference_room:
$('.form-field.request_subject').hide(); // Hide subject
$('.form-field.request_description').hide(); // Hide description
$('#request_subject').val('Conference Room Setup'); // autofill subject
$('#request_description').val('test description'); // autofill description
}
});
0
31 comments
Jessie Schutz
Hey Matthew! We've got a couple Moderators who are good with JS...I'll see if they're available to hop in here for you!
0
Dan Cooper
Hi Matthew,
I found an example that might be able to help you get your drop-down working to update your subject and description. I use a similar setup for hiding and pre-filling the subject and description on my forms based on the form that has been selected. I haven't done the same for a custom drop down, but this example might be able to help you on your path to accomplish this.
Example via Stack Overflow
0
Dan Cooper
Here is the example of what we do based on the Ticket Form drop down. If a specific form is selected this runs from the JS tab.
var ticketForm = location.search.split('ticket_form_id=')[1];
if(ticketForm == 172283) {
$('#request_subject').val('Attendance Line Event');
$('#request_description').val('Updating Attendance Line...');
$('#request_subject').parent('.request_subject').hide();
$('#request_description').parent('.request_description').hide();
}
0
Jessie Schutz
Hey Matthew!
Did this answer your question?
0
Martin Sachs
I'm interested in this as well. Would love to hear if it worked before I give it a stab.
@Daniel - I'm trying to take this one step further and trigger the answer suggestions. I can get the form to render with the subject like in your example but answer suggestions don't trigger unless I take manual action in the subject field.
What I'm trying to do is marry this whole process together. I have a custom field with nested values that helps inform us of the issue - I want to populate the subject based on that field and then have suggested articles show up to help deflect the submission.
Any guidance on how to trigger the suggestions programmatically?
0
Dan Cooper
Hi Martin,
I wish I had an answer here, but my solution was also diving into a new skill set for me. I haven't had to dig that far just yet. I would probably start by digging into the default Javascript in the theme to see if there is something controlling when the suggested articles present and work from there. I'm hoping someone else that knows a bit more about this can answer your question. I'd love to know this myself.
0
Juliano
Hey Martin, this is exactly what I need too.
Did you have any luck with this?
0
Lila Kingsley
Hi,
My need on the new request form is to have the custom field drop down value chosen by the user populate the subject (so we can hide the the subject on the form).
I'm able to hide the subject using the "// Hide subject" code in the help center script.js as referenced in the Answer section of this article: https://support.zendesk.com/hc/en-us/articles/115002860148-Disabling-the-subject-and-description-fields-on-the-new-request-form-in-Help-Center-
The article shows how to populate subject with a text string and it works fine, but, I'm not able to find anything in ZD support on using another field value (specifically a drop down) to populate subject. Though I see several references to it on the web which make it look possible...but I can't get them to work
Can anyone advise how to accomplish populating the subject with the value selected in the custom drop down field?
0
Jacob the Moderator
Hi Lila,
You should be able to update a system field, like the subject field, with the input from a custom field, using a trigger notifying a target with the custom field's placeholder value.
Note: this is not recommended by Zendesk (although I do have something similar working reliably).
There's a pretty good guide for doing something like this here, although it is for different fields - it should give you an idea of what's involved.
For the URL target the settings should be the following:
Title
Url
Method
Attribute name
Basic Authentication
Use your admin credentials to authenticate the target.
Hope that helps you out! Let me know if you need more details.
0
Lila Kingsley
Thanks Jacob! Not sure this will work for me, as our need is to populate the subject field with the selected custom field drop down value BEFORE the HC "new request" ticket form is submitted (subject is required at submit in the form by ZD and that cannot be changed). Since your solution uses a trigger, I believe it requires the ticket to exist.
Do you have experience using your solution in this scenario (populating subject field behind the scenes/hiding from customer before the HC ticket is submitted)?
0
Jacob the Moderator
Hi again Lila,
A trigger can perform action events upon ticket creation as well as updates, no problem there.
We use almost the same thing for tickets requested through the Web widget - overwrite the original subject text with one from another field, and it works for us. As long as you have a placeholder available for the field input you'd like to use as the new subject text, it should work just fine for you as well.
0
David Edgson
I don't know if you ever got your answer for this, but this is something we did.
We hide the Subject field, and code similar to the following to set the Subject value when the user hit's submit on the request. Instead of the static value you see below, we actually populate the subject value variable by combining the values of several custom fields the user fills out on the form.
var subject_value = "Insert Subject Value Here";
$("#new_request").submit(function(e){
$('#request_subject').val(subject_value);
});
0
Jessie Schutz
Thanks for sharing your solution, David!
0
William Grote
Hi Dan
To hide and then autofill the subject with the name of the form, do you have to copy and paste that code you shared with the form ID for each form, or is there a way to do it so the name of any form picked from the initial form DD will get auto-filled to the subject line, that is the solution I am seeking
thanks
William
0
William Grote
Scratch that, I just need to hide the subject field and then auto fill it when its submitted with the value from a custom drop down field (in this case, the drop downs lists the common support topics for this specific form - for this form there are 8 'topics' which are in essence, the subject anyway
So without having to add the specific code snippet for each possible variation, is there a way to grab the value and have it populate automatically, based on the value that the end user picks from the drop down?
0
David Edgson
That's what we do in our zendesk. we hide the subject field and populate it at the point of submitting with values the user entered into other fields. This example creates a subject like "New User John Doe 2019-01-01"
So in addition to hiding the fields like Dan does, we add this code that sets the subject field upon submitting the ticket.
$("#new_request").submit(function(e){
//33860927 = FirstName
//33855548 = LastName
//33855528 = FirstDayOfWork
var subject_value = "New User " + $("#request_custom_fields_33860927").val() + " " + $("#request_custom_fields_33855548").val() + " " + $("#request_custom_fields_33855528").val();
$('#request_subject').val(subject_value);
});
0
William Grote
Hi David,
thanks for the input, im just learning this trial and error, I have never coded a thing before so this is like learning German in an afternoon
I came across another post that changes the description value rather than hiding it, but it doesnt work when I tried to use the same code for the subject I entered this using the field ID from my custom drop down where the bold text is
$("#request_custom_fields_yournewfieldnumberhere").change(function() {
var newsubject = $(".request_custom_fields_yournewfieldnumberhere a").html();
$('#request_subject').val(newsubject);
});
it did not work,
All I want to do is the following, - if someone could help me with the code exactly as I need to past it into the JS Tab
If a certain form is picked ( I have custom forms for each version of our product requiring support)
Then hide the subject from the form, and upon submission, use the value from the custom drop down on that form to fill in the value for the subject so that the agent sees it
David, having used ZD for a while, your code to make the subject immediately fill with the new requester info is fantastic from an agent perspective, Kudos!
0
William Grote
When the subject field is auto-filled, the answer bot not longer suggests articles based on key words, has anyone found a solution to this or a way to have the answer bot suggest articles based on the description rather than the subject?
0
Brett Bowser
Hi William,
Answer-bot should look at both the Subject and Description of the ticket as mentioned in the following article: What part of a ticket does Answer Bot use to determine which articles to suggest?
If you're using custom code that may be affecting the results of answer-bot. I won't be able to assist myself but it may be helpful if you provide the code you're using so other members can take a look for you.
Thanks!
0
Ricky Bello
We hide the Subject and Description and we're able to assign static values for them but we're trying something similar to what David has where the subject field is set upon the ticket submitted and 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.
0
Brett Bowser
Hey R. Bello,
I replied to your post here and added your question to our community roundup for August: Auto-populating fields in ticket forms with custom field input data
I also see you created a ticket for our Customer Advocacy team to look at. Someone from the appropriate team will reach out to you regarding your question :)
Cheers!
0
Danny Koss
I've had success in auto-setting the subject based on the selected field using code similar to:
$("#new_request").submit(function(e){
var subject_value = $("#request_custom_fields_xxxxxxx").val();
$('#request_subject').val(subject_value);
});
When the ticket comes into Zendesk Support, the subject of the ticket is the tag of the custom field. Is there a way to have the subject set to the user-facing value of the field as opposed to the tag?
0
Brett Bowser
Hey Danny,
I'm rather limited in the custom code field but it may be worth taking a look at the available placeholders for custom fields here: Using placeholders
Hopefully, other users can jump in and offer up some advice on how to get the ticket value displaying instead of the tags.
0
Danny Koss
Thanks, Brett. In reviewing this documentation, it looks like there is a "name" object which maps to the title of the selected field.
https://developer.zendesk.com/rest_api/docs/support/ticket_fields#updating-drop-down-field-options
I haven't had any luck yet in getting the subject to be set as the name/title as opposed to the field tag.
0
Greg Siegel
I have a very similar request, and I have tried to get it working based on the comments here, but I have been unsuccessful. What I would like to do is simply make the subject of the email equal the form name. For example, for a ticket being issued in the screenshot, the subject of the ticket should be: "Guide Test"
2
Lila Kingsley
We've since changed our contact form but the following worked for us to hide the default ZD subject field and set it to a custom drop down field value selected by the end user at submit (we also renamed the page in the broser tab).
<script>
$(document).ready(function() {
document.title = 'xxxxxxxxxx'; // Sets custom page name for browser tab (Default = "Submit a request - Your Help Center Name")
$('.form-field.string.required.request_subject').hide(); // Hides contact form subject field
});
$('#request_custom_fields_xxxxxxxxxx').change(function() {
var subject = $('.nesty-input')[0].innerHTML;
$('#request_subject').val(subject); // Sets Subject = to Custom Field Drop Down Item Chosen
});
</script>
1
Dave Foster
There's one thing that is a big downer about using this code to hide the system fields. If you have any Required Fields, and the customer doesn't fill it out, once the system reloads the page to show the warning that the field cannot be blank (or whatever the requirement is), it drops the ticket form id from the URL. Once this happens, all the hidden fields will show back up, including any custom text you've added to said fields.
0
Nick Vincent-Maloney
I wanted to do something similar... I have several "forms" that will create different types of tickets, and I want to auto-fill each subject and maybe description with text... So I did something like the below. Note that I used web developer options in Chrome or Firefox to find the dropdown ID, "request_issue_type_select".
If this seems wrong or if anyone thinks it'll cause problems, please let me know.
0
TAN BING
Dear All,
I am able to set value for Subject by below script but unsuccessful for Description. Would you please help me. I was stuck here few days already.
The end-user interface as below.
The code in script.js as below.
0
Sam
@... Do you have brackets to close out those functions below the screenshot, and single quotes instead of double for the #request_description? If not, it should be something similar to:
The following works on my end:
(Note that in the above example, I use the Ticket Form text instead of the form ID.)
0