logo

NJP

User information in Catalog Client Scripts

Import · Jun 05, 2019 · article

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.

image

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

View original source

https://www.servicenow.com/community/now-platform-articles/user-information-in-catalog-client-scripts/ta-p/2310261