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 support third-party technologies such as JavaScript, jQuery, or CSS. Please post any issues 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:
- Locate the ticket form ID
- Locate the organization name
- Edit the JavaScript
Note: If your theme uses Guide Templating V2, jQuery must be imported. For full details, see the article: Importing or upgrading jQuery.
Step 1: Find the ticket form ID
- Go to Admin Center, navigate to the Ticket Forms page, and select the appropriate ticket form.
- Find the ID number in the URL after the last slash.
Step 2: Find the organization name
- Go to Admin Center, and navigate to People.
- Browse or search for organizations to find the right organization name.
Step 3: Edit the JavaScript
Note: if the user does not copy all characters such as “;” and “}” from the template, the code will not work as intended and may result in preventing the user from accessing the user profile drop-down and seeing things like the My Activities button and the Logout button.
- In Guide, click the Customize design icon (
) in the sidebar.
- 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 organization you want the ticket form to show.
- Paste the code into the JavaScript template of your Help Center code.
- Save your template and publish changes.
The provided code reserves space for other organizations. To add additional forms and organizations, copy the if statement above and place it under the existing if statement 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.
67 Comments
Is it possible to make the "dropdown menu" disappear and just show 1 ticket-form since there is only one to show? I mean I have multiple ticket-forms but they are all hidden and only shown for one specific organization. As shown in the picture below, there is only one ticket-form but still it is in a dropdown menu together with a dash sign (-).
Is it possible to just show the ticket-form and skip the dropdown menu. I've come this far by simply following the instruction above for hiding ticket-forms.
Hi Morteza,
I found this community post that provides insight on how to hide a ticket form selector.
https://support.zendesk.com/hc/en-us/community/posts/4409515399066-How-to-disable-the-ticket-form-dropdown
Please note that the suggestions mentioned in the community post was not created by Zendesk. If you have any questions or issues, please reach out to the post above for further assistance. Thank you!
Hi Gabriel Manlapig, thank you for your help but I would like to hide the dropdown menu in general and not after selecting a form.
So, lets say that there are 3 forms A, B and C. And 3 different companies company1, company2 and company3.
The forms are customized in a way that form A is only shown to company1, form B is only shown to company B and form C is shown to company3. The problem is that when you click on submit, there is still a dropdown menu, when you want different companies to land on their own forms directly and not get a dropdown menu despite having one form to show.
Hi,
I am looking to hide certain custom ticket field dropdown options and some ticket fields based on the form selected, how could I do that?
I'm getting a "$ is not defined" error when following these instructions.
Hey there, I reviewed the comments and couldn't understand whether there is a simple solution to having separate forms for different organizations. In a nutshell, we would like our internal users (Org A) to submit tickets using a designated internal form, while all our customers (external) use a different form. Any help from the great Zendesk community?
Thank you!
Please sign in to leave a comment.