Question
How can I hide ticket forms based on a user's organization?
Answer
Disclaimer: This article is provided for instructional purposes only. Zendesk does not support or guarantee the code. Zendesk also can't provide support for third-party technologies such as JavaScript, jQuery, or CSS. Please post any issues you have in the comments section or try searching for a solution online.
To hide specific ticket forms based on the user's organization name, perform the following steps:
Step 1: Find the ticket form ID
- Click Admin (
) > Manage > Ticket Forms and select the appropriate ticket form.
- Find the ID number in the URL after the last slash.
Step 2: Find the organization name
- Click Admin (
) > Manage > People.
- Browse or search for organizations to find the right organization name.
Step 3: Edit the JavaScript
- In Guide, click the Customize design icon (
) in the sidebar. The Theme page opens.
- Click the theme you want to edit to open it.
- Click the options menu and select Edit Code and select script.js.
- Copy the code block below.
$(window).on('load', function() {
var i = 0;
var checkExist = setInterval(function() {
i++;
if ($("a.nesty-input").length){
clearInterval(checkExist);
$("a.nesty-input").each(function() {
$(this).bind( "click", function() {
for (var c in HelpCenter.user.organizations) {
if (HelpCenter.user.organizations[c].name !== "ZENDESK"){
$("#TICKET_FORM_ID").remove();
}
//reserve space for additional organizations
}
});
});
}
if (i > 10){
clearInterval(checkExist);
}
}, 100);
}); - Replace "TICKET_FORM_ID" with the actual ticket form ID.
- Replace "ZENDESK" with the actual organization you want the ticket form to show for.
- Paste the code into the JavaScript template of your Help Center code.
- Save your template and publish changes.
The provided code reserves space for additional organizations. To add additional forms and organizations, copy the if statement above and place it under the existing if statement like below ensuring to replace the ticket form id with the correct one and the organization you want to check and see if the user is in. Repeat this for however many ticket forms and organizations you want.
for (var c in HelpCenter.user.organizations) {
if (HelpCenter.user.organizations[c].name !== "ZENDESK"){
$("#TICKT_FORM_ID").remove();
}if (HelpCenter.user.organizations[c].name !== "MYORG"){
$("#TICKET_FORM_ID2").remove();
}
Note: This workflow doesn't work for unauthenticated users or users who don't have an organization. For these users, all the forms will display.
91 Comments
@Ryan,
Thanks for sharing! As I am not an experienced coder by any means, would you please point out which portions of your code need to be replaced (forms, tags, etc.) within your example before I try to implement it and get something wrong? I tried in testing a bit, but apparently did something incorrect.
Hi Drew,
Using the code as-is, add a prefix to each ticket form name that matches a tag on the users that you want to see that ticket form.
For example:
User John has tag "learner". If you rename a ticket form to "learner - repair form", John will be able to see the form, but other users who do not have the "learner" tag will not be able to see the form.
-Ryan
Ahh - Thanks, Ryan. That makes sense. Too easy - I was trying to over complicate it! :)
Hey Ryan!
Thank you so much for coming back to answer questions about your comment! If you'd like, feel free to write it up for our Tips & Tricks topic. You'll get swag in addition to fame. :)
Hi Ryan!
In the midst of expanding my org's use of ZenDesk to include internal support. I want to create a form that only folks who are tagged with 'isr' (Internal Support Requester) can see. I copied your original code into my script.js file and have renamed a form 'ISR - request', but the form remains publicly available.
Any guidance (though you've provided more than enough over the years!) would be appreciated :)
Best,
Dan
What's the best method for hiding a specific form always, regardless of the user's organization or any other criteria?
I have a form that I'd like to link to from a very specific Help Center article only. I don't want a user to ever be able to select this form from the drop-down list.
Thanks in advance.
Hi Mike!
I imagine that you can use code similar to this to hide the form from all users, rather than just certain users. All this does is remove it from the dropdown so users can't select it - the form still exists, and you should be able to link directly to it. I can't help with code specifics but we have plenty of helpful tips provided by community members that can help get you started!
Hello,
We currently have 1 default form, which all organizations use. We included an additional form for 8 organizations that have an additional service, aside from their current. We used the script above and successfully works. However, is there a method that we can use for all organizations that do not have the additional service that we offer, be directed straight to our default form, instead of having to select the default form from the drop-down menu? Currently, organizations that do not have our additional service, have to click the default form to submit a regular ticket, which is an additional step for them (other form is hidden). Is there a way to show our 8 organizations the two different forms only, and not have the other organizations have to select the only form that they need to submit a ticket and just be directed to the default ticket form?
Thanks.
I would give those users a direct link to the specific form rather to the forms page
Pew. This was advanced for a much needed feature. Would be so much nicer if one it was possible to do this right from the admin interface, where i create the ticket forms, a field "show only for these organisations" and "show only for users with these tags", or something similar.
@Ryan, thanks for sharing your code.
Does it mean that all users shall have a tag corresponding to the prefix of every form they need to access ?
For example :
I have a form called "General" and i want all my users to be able to access this form. So, with your code, all my users shall have a tag "General"?
The problem would be forgetting to add this tag when we add 1 new user.
Thanks in advance
We have implemented this, and it is mostly working well. However, it seems that remove() is not supported on IE11, so users are seeing multiple forms for this.
https://stackoverflow.com/questions/20428877/javascript-remove-doesnt-work-in-ie
So far the suggestions in the above article haven't worked. Does anyone have any other thoughts?
Can anyone help me with the JS i would need for the following? I've read through most of the previous comments and most of the modifications don't seem to quite match up with what i need.
We only have two forms. Our default and "form2". Basically we only want users with a specific user tag to see "form2" in addition to our default form. everyone else without this tag would only see the default form.
Thank you in advance for any assistance.
Hi Wesley,
This should point you in the right direction.
⚠️This snippet of code is quickly written, have your developer check against this.
Can we hide a ticket form from the drop down for ALL users regardless of org? The form would only be accessibly via a direct link...
Kay Thank you, that worked like a charm with some slight modification.
Hi folks,
Looking for some advice on hiding a button on our home page (essentially submit a request) unless it is a specific Organization (either by ID, name or Tags).
So far I have given the button an ID 'tamper' on the home page:
So far so good. I'm having trouble getting a function into the javascript to work. So far I have tried Robberts code with alteration (in bold):
But I can't seem to get it to work. Where abouts in the the JS would this function need to sit?
Hey Alex,
I'm rather limited on what I can assist with on my end but I was able to track down the following tip that may help point you in the right direction:
Hide/show community based on organization tags
Hopefully, other users can jump in and offer up some guidance as well :)
Cheers!
Hello,
This JS workaround works well for forms on the Help Center, but what about forms in the Widget?
Is there a way to interact with the widget's code to add the relevant JS to hide some of the forms depending on the current user's organization?
Hey @Jaïs Pingouroux
You should be able to combine the tip from Brett, with some other custom Widget Scripting.
So in the If check in the JS, you could add the something like this:
#helpsome regards,
Simon Blouner
Zendesk Consultant @ helphouse.io
Thanks Simon Blouner, I'll see if I can use that when the widget is set on a platform with a JWT token
Is there a way to hide the forms from indiividual end-users?
Example, I want Jane and John Doe only to see User access forms. I do not want them to submit any other type of tickets.
Let me try Kay's entry and come back to this post.
Here's my solution that allows you to define a form name:
'Form Name [ONLY: Organization-here]'
Which will make the form appear only for an end-user (or agent) from that organization.
This way you don't need to manage tags or groups, just limit forms to specific organizations.
Source code is available here
So help me understand this a little better. It removes visibility of a ticket from a specific group.
I have specific forms for our HR Dept. We have all our users grouped into orgs that match their departments. With this coding, I will have to list out every org EXECEPT HR and also list out the hr specific ticket forms so that those orgs don't see the HR forms. Right?
Can this coding accept multiple orgs and forms in the same block section or will I have to do this one org at a time?
David Quiram
By default - all forms are available to everyone.
But if you name the form with "[ONLY: organization]" - only members of that organization will see the form.
Example:
1. Incident Form
2. Incident Form [ONLY: HR] <-- will be available only to a user who has "HR" in the list of organizations.
Currently it supports just one Organization, but I can modify it to support multiple orgs so it will be
"Incident Form [ONLY: HR,Finance,Helpdesk]" if that helps.
Kay Thank you for your code to help hide a form based on a user tag. It worked great! We don't have a developer onsite so pardon my question - how could we update it to exclude multiple forms based on a user tag?
Update - I think I'm good now. I was able to hide multiple forms finally. :-)
Glad to hear you got things sorted, Judy!
Also, I see that this is your first post. Welcome to the Zendesk Community! If you'd like to introduce yourself to everyone, you can do so here.
Lior Broshi Where do I insert the code you listed above?
Seth Weingarten at the end of script.js of your template.
Please sign in to leave a comment.