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

Create a customized support experience. Present only relevant ticket forms to customers on the 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: This workflow doesn't work for unauthenticated users or users who don't have an organization. For these users, all forms display. Note: If the theme uses Guide Templating V2, you must import jQuery. This code doesn't apply for Guide Templating V4. For full details, see templating versions for help center themes.
Disclaimer: Use this article for instructional purposes only. Zendesk doesn't support or guarantee the code. Zendesk also can't support third-party technologies such as JavaScript, jQuery, or cascading style sheets (CSS). Post any issues in the comments section or search for a solution online. You also may not be able to use this code if you have a custom theme for the help center rather than the default Copenhagen theme code.

Expand all tabs



document.addEventListener('DOMContentLoaded', function () {
const toggleBtn = document.getElementById('master-toggle');

toggleBtn.addEventListener('click', function () {
const action = this.getAttribute('data-action');
const headers = document.querySelectorAll('.accordion');

headers.forEach(header => {
const isActive = header.classList.contains('active');
const panel = header.nextElementSibling; // Grabs the corresponding .panel container

if (action === 'expand' && !isActive) {
// Open it by simulating a standard click
header.click();
} else if (action === 'collapse' && isActive) {
// Close it by simulating a standard click
header.click();
}
});

// Flip button text and states
if (action === 'expand') {
this.setAttribute('data-action', 'collapse');
this.textContent = 'Collapse all tabs';
} else {
this.setAttribute('data-action', 'expand');
this.textContent = 'Expand all tabs';
}
});
});
Step 1: Find the ticket form ID

In Ticket forms, open the appropriate ticket form
In the uniform resource locator (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 the theme uses Guide Templating V2, you must import jQuery. For full details, see 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 don't support DOMNodeInserted, follow the Mutation Observer guidance and migrate to a newer function.
To edit the code:

In Knowledge, click the Customize design icon ( ) in the sidebar
Click the name of the theme you want to edit
Click the options menu, 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 =&gt; 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 the 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 you don't copy all characters such as ; and } from the template, the code may break the page
Save the 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. Replace the ticket form ID with the correct one and the organization you want to check. 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();
}
