Incident Category choices hide/show for different groups, roles, group type etc.

Johannes Coetse
Kilo Expert

My organisation (a University) is planning to expand ServiceNow from IT to more departments which will use it for Incident and Request management. Domain separation is costly and also does not make sense since we eventually want the ServiceNow portal to be the only point of contact any person will need.

Making use of business rules, some reference qualifiers etc, the split is looking quite good but hitting a wall with the Incident Categories. I'd like to keep it to one choice list, filtered depending on the supporter logged in e.g. hasRole and thus either see or don't see certain choices. 

I managed to do this with an onLoad client script and it works well, but to split IT from a single other department is a lot of repetitive code and all this runs on client side through all the code, worrying it might hinder the user experience too:

function onLoad() {


     var isIct = g_user.hasRole('ict_itil');
	if (isIct == true)
	return;
	var isCtl = g_user.hasRole('u_ctl_itil');


     var incidentCategory = g_form.getValue('category');


//if (!isIct && incidentCategory != u_servers)
     if (isCtl && incidentCategory != 'u_servers'){
		 g_form.removeOption('category', 'u_servers');
	 }
		  if (isCtl && incidentCategory != 'u_audio_visual'){
		 g_form.removeOption('category', 'u_audio_visual');
		  }
			  if (isCtl && incidentCategory != 'u_desktop_software'){
		 g_form.removeOption('category', 'u_desktop_software');
			  }
				  if (isCtl && incidentCategory != 'u_server_software'){
		 g_form.removeOption('category', 'u_server_software');
				  }
					  if (isCtl && incidentCategory != 'u_end_user_computing'){
		 g_form.removeOption('category', 'u_end_user_computing');
					  }
						  if (isCtl && incidentCategory != 'u_ufs_security_technologies'){
		 g_form.removeOption('category', 'u_ufs_security_technologies');
						  }
							  if (isCtl && incidentCategory != 'u_ict_network_infrastructure'){
		 g_form.removeOption('category', 'u_ict_network_infrastructure');
							  }
								 if (isCtl && incidentCategory != 'u_communication_telephony') { 
		 g_form.removeOption('category', 'u_communication_telephony');
								}
								  if (isCtl && incidentCategory != 'u_core_applications'){
		 g_form.removeOption('category', 'u_core_applications');
								  }
									  if (isCtl && incidentCategory != 'u_support_applications'){
		 g_form.removeOption('category', 'u_support_applications');
									  }
										  if (isCtl && incidentCategory != 'u_email_calendar'){
		 g_form.removeOption('category', 'u_email_calendar');
										  }
											  if (isCtl && incidentCategory != 'u_ict_security'){
		 g_form.removeOption('category', 'u_ict_security');
											  }
												  if (isCtl && incidentCategory != 'u_backup_storage'){
		 g_form.removeOption('category', 'u_backup_storage');}

		 
	//else if (!isCtl){
//  	 g_form.removeOption('category', 'u_servers');
// 		 g_form.removeOption('category', 'u_audio_visual');
// 		 g_form.removeOption('category', 'u_desktop_software');
// 		 g_form.removeOption('category', 'u_server_software');
// 		 g_form.removeOption('category', 'u_end_user_computing');
// 		 g_form.removeOption('category', 'u_ufs_security_technologies');
// 		 g_form.removeOption('category', 'u_ict_network_infrastructure');
// 		 g_form.removeOption('category', 'u_communication_telephony');
// 		 g_form.removeOption('category', 'u_core_applications');
// 		 g_form.removeOption('category', 'u_support_applications');
// 		 g_form.removeOption('category', 'u_email_calendar');
// 		 g_form.removeOption('category', 'u_ict_security');
// 		 g_form.removeOption('category', 'u_backup_storage');

}

What other option do we have? I thought ACL on choice table, adding a role field there and binding choices to roles and thus the Category field choices will just show those you have access to, but I can't get that to work.

Is there any arguments or script includes that would work better, maybe even a business rule?

Thanks in advance for any inputs.

Johannes Coetsee

 

5 REPLIES 5

AshishKM
Kilo Patron
Kilo Patron

Hi , If you have such long list. you can create a custom table and create all column with required filter data and onLoad get only those records which pass the filter condition. Keeping this data in table will be easy any maintenance work. Any time you can add new/update/delete/ or mark inactive.

 

Thanks

Ashish

Please hit correct/helpful for others ( if it helps you )

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hallo Ashish,

Thank you very much for the reply.

Would I create a new Category field on the Incident table which references the new tables data or just switch the current Category field to the new table?

I'm not sure how creating a new table with columns (attributes on record) is different to using the choice table? Is your suggestion to rather create a new custom table to suit our need than modify the choice tables with elements Category?

 

If we do go down the new table road, what field type would be the best attribute to use to identify a user role and thus easily filter the records onLoad? Do I create a attribute which references for e.g. the sys_user_role table or create my own attribute choices?

I'd like to do this right the first time and not realise in a year that I should have done it differently.. 

Gene1
Tera Contributor

Hi Johannes,

I had a similar requirement from a customer recently.  Below is what I came up with ( it also addresses your concern about browser performance/user experience by making an AJAX call to a server side script include):

 

Onload Client Script:

Table: Incident

function onLoad() {
var ga = new GlideAjax('getCategoryChoices');
ga.addParam('sysparm_name', 'getIncChoices');
ga.getXML(showMessage);
}

function showMessage(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

var isITIL = g_user.hasRole('itil');
var categories = g_form.getValue('category');

if (isITIL && (categories = 'software' || 'hardware' || 'inquiry' || 'network' || 'database')) {
g_form.removeOption('category', 'software');
//g_form.removeOption('category', 'Other');
g_form.removeOption('category', 'inquiry');
g_form.removeOption('category', 'hardware');
g_form.removeOption('category', 'network');
g_form.removeOption('category', 'database');

}
}

 

Server side script include: called getCategoryChoices

Client callable: true

var getCategoryChoices = Class.create();
getCategoryChoices.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getIncChoices: function() {
var glideRecord = new GlideRecord('incident');
glideRecord.query();
glideRecord.next();
var choices = glideRecord.category.getChoices();

return choices;
},

type: 'getCategoryChoices'
});

 

If your list is too long, I would recommend Ashish's suggestion about a custom table.

 

Gene

Hi Gene,

 

I will definitely take a look at this. As I understand this addresses the performance issue but it's still going to be some upkeep to maintain the list?

What is considered too long a list? 

 

Regards,

Johannes