Recent searches
No recent searches
Append custom field values to form submissions
Answered
Posted Jul 18, 2023
We are pulling in some session data from our platform to give our agents more insight into the user's issue without the need for back and forth. That data is being captured in custom fields on the form. I would like to append this information to the description of the ticket on submission of the form so that the agent can see this information and still work off of their default ticket form rather than having to switch back and forth between the two. This is what I have so far in the .js file on our guides sandbox. Nothing seems to be working. I was wondering if maybe the script should employ placeholders instead, but I'm not sure how to do that in JS.
$(document).ready(function() {
var selectElement = $('#request_issue_type_select');
if (selectElement.length) {
selectElement.on('change', function() {
var selectedOptionValue = $(this).val();
var form = $('option[value="' + selectedOptionValue + '"]').data('url');
if (form) {
form.on('submit', function(e) {
e.preventDefault();
// Retrieve field values from Zendesk form
var fieldValue1 = $('#request_custom_fields_123').val(); // Replace 'field1' with the ID or selector of the first field
var fieldValue2 = $('#request_custom_fields_456').val(); // Replace 'field2' with the ID or selector of the second field
// Construct the concatenated string with line breaks
var concatenatedValues = 'Field1: ' + fieldValue1 + '\n' +
'Field2: ' + fieldValue2 + '\n';
// Get the description field element and append the concatenated values
var descriptionField = $('#description-field'); // Replace 'description-field' with the actual ID or selector of your description field
if (descriptionField.length) {
descriptionField.val(function(index, currentValue) {
return currentValue + concatenatedValues;
});
}
// Submit the form
form.get(0).submit();
});
}
});
}
});
2
5
5 comments
Stephan Marzi
Dear Chris,
I am only a sales guy and do not have any experiences in JS, but is the usage of the brackets/ clamps correct?
Please try the following: "{{ticket.status}}"
Regards, Stephan
0
Brandon (729)
Hey Chris,
You could try hiding the description field and populating it exclusively from the other values, rather than trying to combine description and custom field. Details here: https://support.zendesk.com/hc/en-us/community/posts/5050937568666-Prefill-and-hide-Subject-Description-fields-of-specific-form-on-New-Request-Template
That said, I'd suggest there is a bigger goal here of consolidating your use of forms, to have the agents work off the same form as the user submits the request on, thus reducing the need to flip back and forth or share data between the different elements inside of the Agent Workspace.
Brandon
0
Brandon Taylor
Hi Chris,
Another option for this would be to use a third party automation system such as Zapier (which has excellent integrations with Zendesk) to accomplish this by looking for that custom form information then updating the ticket with the revised subject.
I hope this helps,
-Brandon
0
Chris Gregory
{% if ticket.ticket_field_321 contains 1 %}
**IP Ranges:** {{ticket.ticket_field_123}}
{% endif %}
0
Chris Gregory
Target is https://subdomain.zendesk.com/api/v2/tickets/{{ticket.id}}.json?ticket[comment][public]=false
PUT
ticket[comment][body]
I got that from a fellow on a different thread but I cannot find it now.
0