petercawdron
Kilo Guru

By default, ServiceNow loads up the angular scope object in the client browser with EVERY value on the sys_user table for each user, meaning there is NO reason to ever do a server call for anything relating to the current user.

find_real_file.png

Instead, if you add this code to your on load catalog client script, you can retrieve anything you want about this user.

function onLoad() {

	var myWindow = (0, eval)('this');

	myWindow.getScopeVariable = function(whichValue){
		var win = (0,eval)('this');
		var ngMain  = win.angular.element('main');
		//if you're curious about what's available
		//console.log(ngMain.scope());
		return ngMain.scope().user[whichValue];
	};
}

Then, in any other catalog client script, you can retrieve details (system fields or custom fields) without the need for a server call. From there, you can push these into g_form values, etc.

var manager      = getScopeVariable('manager');
var managerName  = getScopeVariable('manager_dv');
var specialGroup = getScopeVariable('u_specialist_group');
//or whatever your custom fields on sys_user actually are..

Have fun

Version history
Last update:
‎06-05-2019 06:40 PM
Updated by: