Zendesk API Autofill ticketfield based on customfield



Publication le 17 oct. 2023

Dear Community,

I'm currently working on configuring our script.js file. Many of our formulas do not require customers to input any messages in the description field, which is why I have currently hidden this part. However, as this field is mandatory, I'm currently inputting a constant string "Custom Field text."

I would like to replace this constant text with a variable that depends on the customer's input in a customField. The text in the customField and the description field should be identical.

Here is my current code, which I borrowed from the community moderator, Ifra Saqlain

document.addEventListener("DOMContentLoaded", function () {
    function checkTicketId(){
        var descriptionWarpper = document.querySelector('.form-field.request_description');
        var descriptionField = document.querySelector('#request_description');
        var descriptionLabel =  document.querySelector(".form-field.text.required.request_description > label");
              var attachmentWarpper = document.querySelector('label[for="request-attachments"]');
            var dropzoneWarpper = document.querySelector('#upload-dropzone'); 
     
          descriptionWarpper.style.display= "block";
              descriptionLabel.innerHTML = 'Beskrivelse';
      
     if(window.location.href.indexOf('14154610162461' ) > 1) {
        descriptionWarpper.style.display= "none";
          descriptionField.innerHTML = "Custom Field text";
           attachmentWarpper.style.display= "none";
                    dropzoneWarpper.style.display= "none";
     }  else if(window.location.href.indexOf('14154601112989') > 1) {
         descriptionWarpper.style.display= "none";
        descriptionField.innerHTML = 'Custom Field text';
              attachmentWarpper.style.display= "none";
                        dropzoneWarpper.style.display= "none";
     } else if(window.location.href.indexOf('14200136091677') > 1) {
         descriptionWarpper.style.display= "none";
        descriptionField.innerHTML = 'Custom Field text';
            attachmentWarpper.style.display= "none";
                        dropzoneWarpper.style.display= "none";
     }
     }
    
    checkTicketId();
});

0

4

4 commentaire

Thank you so much! You are indeed a saint

Sorry for the late response, but i havent had the time to try out your solutions, but i works perfectly. 

In the meanwhile i also got the need for beeing able to check off a checbox, whenever the input value is grater than 28. I made i work with checking off the checkbox, when you are typing the number, but whenever you are using your mouse to incrument the value inside the number-box, i will not effeect the checkbox. 


Furthermore i can visually see the box beeing checked off ,but another field keeps beeing hidden. I have another field that should appear when the checkbox are cheked. 

Best regards Mathias





0


Hi Mathias Katz Sørensen,

Try this code once for -- pseudo code:

If (Formular ID == 111111) do this:
Get string-value from custom text field
Save string-value in a string-variable

Input string-variable into the description_field

 

Code:

 if(window.location.href.indexOf('360003074611' ) > 1) {
      $(function() {
          $('#request_custom_fields_10341238690708').keyup(function() {
              var value = $(this).val();
              $('#request_description').val(value);
          }).keyup();
      });
     
     $('.form-field.request_description').hide();
     $('#request_description').hide();
     $(".form-field.text.required.request_description > label").hide();
     $('label[for="request-attachments"]').hide();
     $('#upload-dropzone').hide();
   }

 

JQuery CDN - add to document_head.hbs file.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

 

And ,also I found this article :

https://support.zendesk.com/hc/en-us/community/posts/4408860835226-Need-help-in-copying-a-ticket-field-s-value-to-another-ticket-field

 

Thanks

 

0


Hi Ifra

So my request, can seem kinda odd, as I easily  would be able to tell the end-user to input the string direcly into the description_field, which would in some sense be much easier. However i would like to have the information 2 Places at the same time, as my other configurations are based upon different custom fields.

pseudo code:

If (Formular ID == 111111) do this:
Get string-value from custom text field
Save string-value in a string-variable

Input string-variable into the description_field

I've tried something like: client.get('ticket.customField:custom_field_12345678'), but unfortunatly this didnt work for me.


This is an example of what i tried to fix my issue

document.addEventListener("DOMContentLoaded", function () {
    function checkTicketId(){
        var descriptionWarpper = document.querySelector('.form-field.request_description');
        var descriptionField = document.querySelector('#request_description');
        var descriptionLabel =  document.querySelector(".form-field.text.required.request_description > label");
              var attachmentWarpper = document.querySelector('label[for="request-attachments"]');
            var dropzoneWarpper = document.querySelector('#upload-dropzone'); 

var fieldString = client.get('ticket.customField:custom_field_12345678'):
     
     
      
     if(window.location.href.indexOf('14154610162461' ) > 1) {
        descriptionWarpper.style.display= "none";
        descriptionField.innerHTML = fieldString;
           attachmentWarpper.style.display= "none";
                    dropzoneWarpper.style.display= "none";
     }  else if(window.location.href.indexOf('14154601112989') > 1) {
         descriptionWarpper.style.display= "none";
          descriptionField.innerHTML = 'Custom Field text';
              attachmentWarpper.style.display= "none";
                        dropzoneWarpper.style.display= "none";
     } else if(window.location.href.indexOf('14200136091677') > 1) {
         descriptionWarpper.style.display= "none";
          descriptionField.innerHTML = 'Custom Field text';
            attachmentWarpper.style.display= "none";
                        dropzoneWarpper.style.display= "none";
     }
     }
    
    checkTicketId();
});

0


Hi Mathias Katz Sørensen

If you want user input then comment this code if exists in your theme or do not use it for your theme if you are going to use it

This code is for hiding the fields from some specific forms after filling those required fields.

document.addEventListener("DOMContentLoaded", function () {
    function checkTicketId(){
        var descriptionWarpper = document.querySelector('.form-field.request_description');
        var descriptionField = document.querySelector('#request_description');
        var descriptionLabel =  document.querySelector(".form-field.text.required.request_description > label");
              var attachmentWarpper = document.querySelector('label[for="request-attachments"]');
            var dropzoneWarpper = document.querySelector('#upload-dropzone'); 
     
   
      
     if(window.location.href.indexOf('14154610162461' ) > 1) {
        descriptionWarpper.style.display= "none";
          descriptionField.innerHTML = "Custom Field text";
           attachmentWarpper.style.display= "none";
                    dropzoneWarpper.style.display= "none";
     }  else if(window.location.href.indexOf('14154601112989') > 1) {
         descriptionWarpper.style.display= "none";
        descriptionField.innerHTML = 'Custom Field text';
              attachmentWarpper.style.display= "none";
                        dropzoneWarpper.style.display= "none";
     } else if(window.location.href.indexOf('14200136091677') > 1) {
         descriptionWarpper.style.display= "none";
        descriptionField.innerHTML = 'Custom Field text';
            attachmentWarpper.style.display= "none";
                        dropzoneWarpper.style.display= "none";
     }
     }
    
    checkTicketId();
});

 

 

You can tell me your query so I can find solution for that :)

 

Thanks

1


Se connecter pour laisser un commentaire.

Vous ne trouvez pas ce que vous cherchez ?

Nouvelle publication