How to set role base catogories
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
4 weeks ago
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.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
4 weeks ago
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."
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
4 weeks ago
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!
