Create a customized support experience by presenting only relevant tickets forms to your customers on your help center. In this tutorial you'll learn how to hide specific ticket forms based on a user's organization.
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. Post any issues in the comments section or try searching for a solution online.
The workflow includes the steps below.
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 Objects and rules
- Open 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 Support
- Navigate to Customers
- 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.
Important: This code relies on the DOMNodeInserted Mutation Event. Newer versions of Chrome and Chromium have ended support for this mutation event. To be compatible with browsers that do not support DOMNodeInserted, follow the Mutation Observer guidance and migrate to a newer function.
- 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:
$(document).ready(function() { var formID = 6502769669773; // Change this to the form ID you wish to remove var userOrgs = window.HelpCenter.user.organizations; var userOrgNames = userOrgs.map(org => org.name); if (!(userOrgNames.includes("ZENDESK"))) { // Specify the organization name here // If the user does not belong to the organization specified, remove the form option from the dropdown $('#request_issue_type_select option[value="' + formID + '"]').remove(); $('.nesty-panel').on('DOMNodeInserted', function(e) { $(this).children('ul').children().remove('#' + formID); }); } });
- Replace the
formID = 6502769669773
variable with the ticket form ID you wish to hide - Replace
"ZENDESK"
with the name of the organization that you want the ticket form visible to - 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.
Note: If you would like to change the code's behavior to display one ticket form to all organizations except the one specified, remove the NOT operator
(!)
from the if statement.
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.