Automatically Populate Subject and Description Based on Drop-Down

回答済み


投稿日時:2017年6月05日

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

31件のコメント

Have anyone figured out how to get the suggestion list to show and suggest articles? 

Martin Sachs or William Grote?

0


TAN BING 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:

$('#request_description').val("Test");
} // closes `if` statement for category_1 == function_name
} // closes `change` function
} // closes `if` statement for ticketForm

The following works on my end:

var selected = $('#request_issue_type_select option:selected').text();
if (selected == "Demo form for Zendesk") {
$('#request_description').val("Hello");
}

(Note that in the above example, I use the Ticket Form text instead of the form ID.)

0


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.

 $('#request_subject').val('Customize subject');
$('#request_description').val('Customize description');

The end-user interface as below.

 

The code in script.js as below.

0


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.

// Set the value of the selected dropdown option to a variable
var $request_type = $('#request_issue_type_select option:selected').text();

// Test for option you want, eg, you would have one of these for each form
// you have that you want to auto-fill
if ($request_type == 'Virtual Brunch Sign Up') {
$('#request_subject').val('Virtual Brunch Sign Up');
}

// Conditionally hide description while setting the subject text
if ($request_type == 'Virtual Brunch Sign Up') {
$('#request_subject').val('Virtual Brunch Sign Up'); // Autofill subject
$('.form-field.request_description').hide(); // Hide description
}

0


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


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


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


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


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


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


投稿コメントは受け付けていません。

お探しのものが見つかりませんか?

新規投稿