Forums/Community/Community tips & tricks

How to: Hide specific fields from certain groups of agents

Tal Admon
posted this on August 15, 2012 07:12

If you have multiple agents groups, and you don't want some agents to see some of the ticket fields, you can use the hack below.

In this example, the ticket_fields_21422908 will not be visible to agents who are not in administration group.

 

jQuery(function($) {

var USER_URL = $("a#top-right-name").attr("href");

var PARSED_XML = null;
var DOC_LOADED = false;
var XMLDATA = {};

function parseXml(xml) {
if (DOC_LOADED) {
processXML(xml);
} else {
PARSED_XML = xml;
}
}


function processXML(xml) {
var self = $(this);
var groupname;
var flag = false;

$(xml).find("group").each(function() {
groupname=$(this).find("name")[0].textContent;
if (groupname=="admins") {flag=true;};  //replace admins with your administration group

});

if (!flag) {

$("#ticket_fields_21422908").parent().remove(); //field to be removed 

}

}

function showError(XMLHttpRequest, textStatus, errorThrown) {
//alert(XMLHttpRequest + "--" + textStatus + "--" + errorThrown);
}


$.ajax({
type: "GET",
url: USER_URL,
dataType: "xml",
success: parseXml,
error: showError
});


if (PARSED_XML) {
processXML(PARSED_XML);
delete PARSED_XML;
} else {
DOC_LOADED = true;
}

})

 

Comments

User photo
Jennifer Rowe
Zendesk

Hi Tal, thanks for adding this great tip to our community forum. We just featured it on our Twitter feed and Facebook page. Would love to see a version using APIv2. :) Thanks again!

August 17, 2012 09:36
User photo
Josh Frazier
teleflex

Hi Tal,

Would it be possible for you to share how to modify this script so that it looks at the current group the ticket is assigned to rather than it looking at what group the user is assigned to?

I am wanting to hide fields depending on the group the ticket is assigned to.

August 20, 2012 17:52
User photo
Tal Admon
qualisystemscom

@Josh, I am not sure it's possible with my approach, as I only check the user data, not the ticket information.

August 22, 2012 10:51
User photo
Dan Goldman
wealthvest

Hi Tal,

Could you provide some guidance on how to use and implement this?

Thanks.

September 10, 2012 17:46
User photo
Tal Admon
qualisystemscom

for this to work, the scenario is:

1. administrator agents group

2. other group of agents

3. administrator is in both groups

4. other agents are not in administration group

5. you want to expose (some of the) a ticket fields only to users in administration group

 

You will need to create the groups, users, and the fields themselves.

The administration group should be populated in this line of code:

if (groupname=="admins") {flag=true;};  //replace admins with your administration group

 

once the field is created, it will have an ID in the URL after you click on "edit" - ticket_fields/21414228/edit

 

This is the ID that you will replace in the code.

$("#ticket_fields_21422908").parent().remove(); //field to be removed 

September 13, 2012 09:28
User photo
Robin Laurén

This looks amazing -- but where exactly am i supposed to put this code? And how? And, if you pardon my nubicity, where will i find the numeric field ID suggested above? I know my field-to-hide isn't going to be 21414228...

So much to learn!

 ~robinL

October 03, 2012 03:49
User photo
Tal Admon
qualisystemscom

You'll have to create a new global javascript extension from the "Settings" menu.

Paste the code there.

To get the field ID, go to "Manage > Ticket Fields" and edit the required field. You'll find the ID in the URL, like so:

http://XXX.ZenDesk.com/ticket_fields/21414228/edit

 

 

October 03, 2012 06:05
User photo
Robin Laurén

Thank you, Tal! I shall have a look rightaway!

October 03, 2012 06:09
User photo
Dan Goldman
wealthvest

Tal,

Can you provide nay guidance on how to set fields to default values? The use case is to set default values for required fields for other groups that are hidden from the screen.

Thanks.

October 05, 2012 16:14
User photo
Paul Leverett
i2owater

Excellent! Works exactly 'as advertised' and is great for hiding clutter from people who don't need to see it.

Thanks for sharing. :)

December 19, 2012 08:46
User photo
Tal Admon
qualisystemscom

Thanks Paul.

@Dgoldman - 

To set default values to textual fields, use the .val function:

To set a default option on a combo-box, add "selected" attribute (and remove the null option).

See examples below:

if (!flag) {

$("#ticket_fields_21422908").parent().remove(); //field to be removed 

$("#ticket_subject").val("[IT] - ");  //This will add a prefix "[IT] - " to the ticket subject

$("#ticket_fields_21413096>option[value='4__medium']").attr("selected","selected"); 
$("#ticket_fields_21413096>option[value='']").remove();

}

December 19, 2012 08:58
User photo
Justin Seymour
Zendesk

Thanks for updating, Tal! 

December 19, 2012 12:08
User photo
Dipti Raisoni
synechron

Hello Tal,

I am looking at achieving this on end user form.

 

Certain field should be hidden when the user selects either: Admin. IT, HR from the drop down field

Because each support function has their own work flow with different fields.

 

Can you throw some light on this?

January 04, 2013 07:07
User photo
Andrew

Should this work under the new ZenDesk interface? Can't seem to make it function for me.

I'd really like something like this as a feature of ZenDesk as we are trying to use it for Facilities and Finance departments as well and there are fileds with responses for each departments that shouldn't be seen by the other departments.

January 09, 2013 18:38
User photo
Skip Moore
Zendesk

@Andrew Sorry bu the above code will not work in the New Zendesk interface. The agent interface uses a App interface framework. You can read about the new interface here What you want to do can be done. 

January 09, 2013 20:31
User photo
Andrew

Thanks Skip. Do you know how I can get it done?

January 09, 2013 20:36
User photo
Skip Moore
Zendesk

@Andrew you could make your own using this code as a template https://github.com/skipjac/Zendesk-Apps/tree/master/ConditionalFieldsApp but please be sure to read up on the App documentation  Or just submit a ticket asking for a services engagement and they will find a partner that could code it for you. That will cost some money. 

January 09, 2013 20:53
User photo
Andrew

Thanks Skip. Nice repository. Will have a look.

January 09, 2013 21:09
User photo
Jennifer Rowe
Zendesk

Andrew, if you try to do this yourself, we have a Zendesk Apps community forum where you can ask questions and (hopefully) get help/feedback. And if you do develop this app, be sure to share it--I'm sure everyone would love you! :)

January 10, 2013 13:11
User photo
Kwolinski

If I want the same field visible to 2 groups of agents, should I just create a second widget with the second group ID inserted?

 

Major concern is that the field data will sync properly between the two groups.  Has anyone tried this out yet?

January 16, 2013 10:41
User photo
Larry Weinhouse
zestfinance

Hi Tal,

 

Would you happen to have an update for the New Zendesk Interface?

 

Thanks, Larry

March 10, 2013 20:39
User photo
Kwolinski
Larry,
This actually does work with the new Zendesk, but you have to put the widget in on the old version. The code will transfer correctly to the new interface!
March 10, 2013 20:50
User photo
Lynda Thompson
gtsoftware2

I would really like to know if there is a way to drive additional fields based off of a previously entered field.  Let me detail this out:  We are a software support company with 5 different products.  Based on the product the customer selects, I would like to have the version options populate, as well as the available OS.  Is this possible and how?

April 18, 2013 11:49
User photo
Kwolinski

Lynda- You can add a 'tree' type selection for your customers to use by separating your options out as such:

Product1::Version1::OS

Product 2::Version2::OS

The double colon will create a menu that branches out.  Exact instructions can be found at

https://support.zendesk.com/entries/20611326-Adding-and-using-custo...

 

You could also do a similar approach using a JS widget: https://support.zendesk.com/entries/21044816-Creating-conditional-d...

April 18, 2013 11:57
User photo
Jennifer Rowe
Zendesk

Kwolinski, thanks for helping other users out on this post. Super helpful!

April 18, 2013 13:27
User photo
John Gilbert
technekes

Hey everyone!

I have added the code above as a global javascript widget in both the old and new sites, and updated it with the correct group and ticket field to only show a particular field for a particular group. The field is showing for all agents, not just the one group.

I have refreshed the browser / cleared cache / etc, and I am not seeing any changes.

Any thoughts here would be appreciated!

Thanks in advance!

John

July 26, 2013 07:59
User photo
Kflynn
hpgresources

Is there any way to perform this action but almost in a reverse way? As in, can you make it possible to assign fields to a certain organization instead of having to hide it from everyone else. If it assigned to the one then you wouldn't have to keep adding new organizations to the "hide list."

September 05, 2013 13:48
User photo
Tal Admon
qualisystemscom

@John - make sure your javascript widget is set to `People who have logged in and are agents`
Try checking it on other browser (Google Chrome, for exmaple) - is this still not working?
If you are using IE8, note that textContent is not supported, so my code need to be altered.

@Kflynn - by definition, the javascript widgets are executed after the page was rendered by zendesk. So technically speaking, you can't acheive the reverse effect.

 

September 15, 2013 02:02