Workflow: Hide ticket forms based on a user's organization

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.

The workflow includes the steps below.

Step 1: Find the ticket form ID

Step 2: Find the organization name

Step 3: Edit the JavaScript

This workflow doesn't work for unauthenticated users or users who don't have an organization. For these users, all the forms will display.

Note: If your theme uses Guide Templating V2, you must import jQuery. This code doesn't apply for Guide Templating V4. For full details, see the article: About templating versions for help center themes.

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. You also may not be able to use this code if you have a custom theme for your help center rather than the default Copenhagen theme code..

Step 1: Find the ticket form ID

In your ticket forms, open the appropriate ticket form

In the URL, find the ID number, after the last slash

Step 2: Find the organization name

In Support, open the Customers tab

Browse or search for organizations to find the right organization name

Step 3: Edit the JavaScript

If your theme uses Guide Templating V2, you must import jQuery. For full details, see the article: Importing or upgrading jQuery. The 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 Knowledge, click the Customize design icon ( ) in the sidebar

Click the name of the theme you want to edit

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);
});
}
});

Paste the code into the JavaScript template of your help center code

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

If the user does not copy all characters such as ; and } from the template, the code may break the page

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.

To change the code 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();
}