Forums/Community/Community tips & tricks

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

Mikhail Zakharov
posted this on July 27, 2012 06:43

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"

2. 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")

3. 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>

 

Comments

User photo
Daniel Reed
Synx

Hi Mikhail,

This is a really useful function for our company.  But do you have an updated version that will work for the new Zendesk?

 

Thanks

Dan.

June 03, 2013 04:47
User photo
Skip Moore
Zendesk

@Dan,

We do have a conditional fields for the new Zendesk but that is only agent facing. Mikhails' still will work for customer facing web portal if that is all you need.  

June 03, 2013 08:31
User photo
Mikhail Zakharov
Портал технической поддержки

Hi Daniel,

Thanks to Skip. That's right. This widget for customers portal.  

June 03, 2013 22:55
User photo
Daniel Reed
Synx

Hi,  I'm a little confused.  We have been told that "the new ticket page" is for the old Zendesk and we should not add widgets to the page.

https://company.zendesk.com/request/new

redirects to

https://company.zendesk.com/tickets/new

And if we add items there, they did work for the agent, but not the end user as it's an old Zendesk page.

Also we have an app and javascript widget in place for conditional fields, which we now have working for both the agent and customer. (Selection on the main field causes three new fields to appear - using Skips conditional_fields app - which we now have working with wildcards as well)

Whereas this code provided by Mikhail hides items within a field based on tags which is what we want for our customers portal.

Cheers.

June 04, 2013 00:06
User photo
Daniel Reed
Synx

Hi, I don't think end users have permission to run new Ajax.Request('/users/current.json.

June 07, 2013 08:24
User photo
Skip Moore
Zendesk

If you are using the new Help Center the conditional fields code has changed which can be found here https://github.com/skipjac/Zendesk-Apps/tree/master/conditional-fields-help-center

September 09, 2013 09:21
User photo
xdoomx
mrpgroup

I've implemented on my Zendesk. Can you confirm that this app needs to be installed by every agent in order to work?

November 01, 2013 06:55
User photo
Avi Warner
Zendesk

Brandon, Apps are global. Like our other apps, you should only have to install them on your site (not have every agent install them individually). 

November 10, 2013 14:48