Append custom field values to form submissions

답변함


2023년 7월 18일에 게시됨

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

댓글 0개

로그인하세요.

원하는 정보를 못 찾으셨나요?

새 게시물