5

Conditional dropdown field sample. Conditions based on tags. (Web portal)

Zendesk note: If you are using Help Center, please use this code for conditional fields in Help Center.

Let's see how we can create a conditional dropdown field.

Initial case.
1. You have a two groups of custumers organizations. Enterprise organizations tagged by "enterprise". Small organizations tagged by "small"

  1. You have a dropdown field "Type of service" with items
    a. Ticket support (tagged as "ticket_support")
    b. Request for change (tagged as "request_for_change")
    c. Personal consultation (tagged as "personal_consultation")
    d. Fix bug in place (tagged as "in_place")

  2. And you want to hide c. and d. items from dropdown for organization tagged by "small"

It's not so hard to do as you can think =)

To make it create a Custom HTML widget with next code. And place it to the new ticket page.
NOTE: You should change 21126486 in code to ID of your field.

<script type="text/javascript" charset="utf-8">

Event.observe(document, 'widgets:load', function () {

new Ajax.Request('/users/current.json', {
method: 'GET', asynchronous: true, onSuccess: function (transport) {
var obj = transport.responseText.evalJSON();
org_id = obj['organization_id'];

new Ajax.Request('/organizations/' + org_id + '.json', {
method: 'GET', asynchronous: true, onSuccess: function (transport) {
var obj = transport.responseText.evalJSON();
tags = obj['current_tags'];

// ***** Check the tag "small" *****
if (tags.search("small") >= 0) {
// Remove two items from dropdown
$j("#ticket_fields_21126486 option[value='personal_consultation']").remove();
$j("#ticket_fields_21126486 option[value='in_place']").remove();
};

}
});

}
});
});
</script>

8 comments

Please sign in to leave a comment.