Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to set role base catogories

jui
Tera Contributor

Hi All,

 

I have one requirement in witch I will have to visible some category value for IT agent only not for end user for that I have created many catalog in witch there are couple variables available I want that  some subcategory choices are only visible for IT agent only, please let me know how to solve above requirement.

Kindly find below screen shot for more reference.

 

jui_0-1760122601717.png

 

2 REPLIES 2

vignesh parthib
Tera Guru

Hi @jui 

 

you can create Catalog Client Scripts  : Type: onLoad

Applies to: Catalog Item (select the one you're working on)

whether the current user has the IT agent role (itil). Based on this check, it customizes the available subcategory options:

function onLoad() {
  var isAgent = g_user.hasRole('itil'); // Replace 'itil' with your IT agent role
  var field = g_form.getControl('subcategory'); // Replace with your variable name

  if (!field) return;

  // Clear existing options
  g_form.clearOptions('subcategory');

  // Define your subcategory choices
  var allOptions = [
    {value: '', label: '-- None --'},
    {value: 'email', label: 'Email Issue'},
    {value: 'vpn', label: 'VPN Access'},
    {value: 'server', label: 'Server Issue'},       // Agent only
    {value: 'network', label: 'Network Problem'}    // Agent only
  ];

  for (var i = 0; i < allOptions.length; i++) {
    var option = allOptions[i];

    // Show all to agents; show only selected to end users
    if (isAgent || (option.value !== 'server' && option.value !== 'network')) {
      g_form.addOption('subcategory', option.value, option.label);
    }
  }
}

 

Thanks,
Vignesh
"If this solution resolves your issue, kindly mark it as correct."

aruncr0122
Mega Guru

Hi @jui ,

 

You can control subcategory visibility by role using a Catalog Client Script
Client Script (hide/show choices):
function onLoad() {
var userHasRole = g_user.hasRole('itil'); // or your IT agent role
if (!userHasRole) {
// hide specific choice for end users
g_form.removeOption('subcategory', 'EasyNAC whitelisting');
}
}
Replace 'subcategory' with your variable name and 'EasyNAC whitelisting' with the choice value.

 

Thanks!