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

Johannes Coetse
Kilo Expert

I eventually went with a new Table and Business Unit records created in there. Then referenced these Bu's via a new list field on Task table.

 

Then created some Business Rules to set the Bu on certain conditions and also added Bu as mandatory field on things like Catalog item etc so it must be selected before inserting record. Pass those field values to Req, Ritm and Sc_Task with Before and Async Insert business rules. Async for REQ's since RITMS are created before REQ, thus had to work a bit around it.

Finally once all was setup created new Before Query BR on Task table to query and show only rows based on role. No client scripts used.

 

So now we just add a new line in the BR as each new BU onboards. Theres still lots of fine tuning to do but for now it worx!

 

Final Before Query BR:

if (gs.hasRole('admin'))
{
	//do nothing
}
else{
	if (gs.hasRole("role1"))
	 {
var u = gs.getUserID();
var bu1= 'sys_id of BU table record';

var query = current.addQuery("u_business_unit_list","CONTAINS", bu1).addOrCondition("opened_by", u).addOrCondition("watch_list", u).addOrCondition("caller_id", u).addOrCondition("requested_for", u).addOrCondition("request.requested_for", u);
		
	 }
else{
	if (gs.hasRole("role2"))
	 {
var u = gs.getUserID();
var bu2= 'sys_id of BU table record';

var query = current.addQuery("u_business_unit_list","CONTAINS", bu2).addOrCondition("opened_by", u).addOrCondition("watch_list", u).addOrCondition("caller_id", u).addOrCondition("requested_for", u).addOrCondition("request.requested_for", u);
	 }
}	
}