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.
97 Comments
We would like to make the "Submit a request" link/button in the top navigation only be visible to users of several segments that we can easily define and update with new segments, over time.
Any suggestions or snippets that y'all could share with us?
Has anyone been able to get this to work? I have tried a few solutions from the comments but not having any luck.
Our goal is to HIDE a single form from ALL users, except those with a specific tag. Speaking of tags, is the tag based on user tag? Org tag? User segment name?
What's the best way to accomplish this?
I know of an easy way to hide specific ticket forms from anyone. I use this method because I want some forms to be only available from specific web widgets, while not using brands:
However, this uses JQuery. I would like to convert to VanillaJS but I have failed so far. Does anyone know how to translate this into VanillaJS?
I have managed to "translate" the first part, but I'm still stuck with the $(this).children('ul').children().remove('#TICKET_FORM_ID') JQuery which looks too "complex" to be easily translated. So the code looks like this now:
It works, but it is very ugly since it mixes Vanilla JS and JQuery.
Help on making it 100% Vanilla JS would be very appreciated.
Hi Julien 👋
Almost there.. this should be the final part to remove jQuery completely
Hi Kay,
Wow, you just saved my day (and nights)! This works exactly the way I intend to! Thanks a lot :-)
For the record, here is a "template" snippet if anyone wishes to do the same:
Thanks again to Kay for the help!
Regards
Hi all,
It would be great to have this as native function. Being able to hide or show a form based on organisation would great to have without going to the code. Is there any plans for this?
Please sign in to leave a comment.