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

image avatar

Stephan Marzi

Zendesk Luminary

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


image avatar

Brandon (729)

Zendesk LuminaryUser Group LeaderThe Humblident Award - 2021Community Moderator

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


image avatar

Brandon Taylor

Zendesk Luminary

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


 
 
Hi Brandons!
 
I found kind of a no duh solution to this issue. Instead of focusing on adding field values to the initial comment on the ticket when it comes in through the back end, I created a target for each form that places an internal note on the ticket when it is created that includes the values of all of the form fields and then switches to the team's default form. I know this is not best practice at times, but I do not think this specific scenario creates a race situation as it can only fire when the ticket is created and the field values are already populated.
 
I was also able to streamline this comment dynamically using liquid markup by saying, only list this form if the condition on it appearing is satisfied. In this case it is a checkbox:

{% if ticket.ticket_field_321 contains 1 %}
**IP Ranges:** {{ticket.ticket_field_123}}
{% endif %}
 
It would be pretty sweet in the future if adding an internal comment was just a normal trigger action though.

0


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


Please sign in to leave a comment.

Didn't find what you're looking for?

New post