Recent searches


No recent searches

How to pre-fill description box based on Custom Field value

Answered


Posted Jul 28, 2021

Hi All,

I'm seeking assistance on how to autopopulate the description box based on the value of a particular custom field. This for when an end user submits a form.

The custom field is a drop-down menu containing only 2 options

The Description box has been hidden to let us customise the ticket description.

This is my current code so far:

$('.form-field.request_description').hide();
if ($("#request_custom_fields_360025027158")=="OPTION A") {
$('#request_description').val('Description 1');}
else
{$('#request_description').val('Description 2');}

Any and all assistance would be appreciated.


1

11

11 comments

image avatar

Trapta Singh

Zendesk LuminaryCommunity Moderator

Hi Lou

Try the below code:

tinymce.get("request_description").setContent("<p>Description 1</p>");

Let me know how it goes for you. 

Thanks

0


image avatar

Lou

The Product Manager Whisperer - 2022Community Moderator

When you say description, are you referring to the subject field? If so, we use a trigger and extension to make that change. It's completely automated based on if the field has a value.

0


image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

Hi Patrick Lieu,  I got something for you:

 

HTML: Add at any page

<div id="option1" class="group">Description One</div>
<div id="option2" class="group">Description Two</div>
<div id="option3" class="group">Description Three</div>
<div id="option4" class="group">Description Four</div>
<select id="selectMe">
<option value="option1">option1</option>
<option value="option2">option2</option>
<option value="option3">option3</option>
<option value="option4">option4</option>
</select>

 

Script code:

$(document).ready(function () {
$('.group').hide();
$('#option1').show();
$('#selectMe').change(function () {
$('.group').hide();
$('#'+$(this).val()).show();
})
});

 

 

Output is:

 

I'm not sure but may be you can do something with this code via changing the classes in script code.

You can add script code only and add the classes of your custom dropdown.

Thanks

 

0


Ifra Saqlain the Output image is missing, can you please add. Trying to work out if this will work for our needs. Thank you :)

0


Hello, I am trying to add a description template based on a custom field id's and their associated tags.  I listed custom field 1 and 3.  Custom field 3 is a child field of Custom Field 1.  My code worked fine up until last week.  For some reason it stopped working and also disabled the users dropdown menu to view their activities and requests.

Here is the code I have added into the JS

/*
$(document).ready(function () {
    var ticketForm = location.search.split("ticket_form_id=")[1];
if(ticketForm == 400000000000) {
    $("#request_description").val();
    }
});

function descriptionFormat(){
        let serviceType = { 
          ID Tag1                        : "1. Do you have the current version of the App? (Update version),
          ID Tag 2                       :""
                }
        
        let IssueType = {
          ID Tag3                       : "Does the member have the current App version?
        }
                
    const serviceTypeNode= document.getElementById(document.querySelector("#new_request > div.form-field.string.required.request_custom_fields_ID_1 > a").getAttribute("aria-controls"));
      
    const config = { attributes: true, childList: true, subtree: true };
        
        const serviceTypeCallback = function (mutationsList, observer) {
            for (const mutation of mutationsList) {
                if (mutation.attributeName == "aria-selected") 
                { 
                    if (Object.keys(serviceType).indexOf(mutation.target.id)>=0) {
                  document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = serviceType[mutation.target.id];
                          if (mutation.target.id == "ID_3"){
                          const IssueTypeNode= document.getElementById(document.querySelector("#new_request > div.form-field.string.request_custom_fields_ID#.required > a").getAttribute("aria-controls"));
                          issueTypeObserver.observe(IssueTypeNode, config);
                        }
                    }
                    else {
                        document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = "";
                    }
                }
            }
        };
  
              const IssueTypeCallback = function (mutationsList, observer) {
            for (const mutation of mutationsList) {
                if (mutation.attributeName == "aria-selected") 
                { 
                    if(Object.keys(IssueType).indexOf(mutation.target.id)>=0){
                          document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = IssueType[mutation.target.id];
                    }
                  else{
                          document.getElementById('request_description_ifr').contentWindow.document.querySelector("p").innerText = serviceType["Issue Type Tag"];
                  }
                }
            }
        };
        
        const serviceTypeObserver = new MutationObserver(serviceTypeCallback);
              const issueTypeObserver = new MutationObserver(IssueTypeCallback);
        
        serviceTypeObserver.observe(serviceTypeNode, config);
    }

if (document.querySelector('#new_request a[aria-label="Please choose your issue below"]').innerText == "Form Name 1"){
        descriptionFormat();
}

0


I have a similar ask... Does anyone have experience populating a custom name for the description box, based on a field value?

for example,
if tech support issue = "document upload" then description title reads: "Please provide any details about your document upload"
&
if tech support issue = "platform issues" then description title reads: "Please provide information about the platform you're using"

0


image avatar

Julio H

Zendesk Customer Care

Hi Zach,
 
Thanks for your feedback.
 
This is not currently possible. As a workaround, you can use conditional fields.
 
Creating conditional ticket fields
 
When an end user selects a value from the field support issue. Then the system can show a different type of fields to request different information from each value in that field.
 
For example:
 
If user selects support issue = "document upload" then show the following fields: Do you attach your documents? (yes / no)
 
I hope it helps. 

0


image avatar

Jill Bragg

Zendesk Luminary

Hi Julio,

Is this still a limitation, or is there another way now without using condition ticket fields? I'm trying to do pretty much the same thing as Zach. We need the subject & description fields (as well as the description hint) populated with certain text only when one specific dropdown value is chosen on one of our custom fields. Is there anything that can be added/edited in the code below to make that work?

document.addEventListener('DOMContentLoaded', function() {
if (window.location.href.indexOf("formIdGoesHere") > -1) {
     document.querySelector('#request_subject').value = "CNAM Update Test";
     document.querySelector('#request_description').value = "Please attach your CSV using the template linked below.";
        document.querySelector('#request_description_hint').innerHTML = "<a href='templateLinkGoesHere'><b>Click here for CSV template</b></a>";

I've looked through other posts in the community & on Zendesk's knowledge base but haven't been able to find anything that works. Any help would really be appreciated. Thanks!!



 

0


image avatar

Jill Bragg

Zendesk Luminary

Perfect! Thanks so much for your help Thomas.

0


image avatar

Brandon (729)

Zendesk LuminaryUser Group LeaderThe Humblident Award - 2021Community Moderator

@Thomas beat me to it - and he has a pretty neat newsletter that is worth subscribing to, IMHO.

1


image avatar

Stephan Marzi

Zendesk Luminary

Great community and really great assistance! Thumbs up!

1


Please sign in to leave a comment.

Didn't find what you're looking for?

New post