Requesting more information on glideUserSession for Service Portal - anyone familiar?

JZX81
Kilo Contributor

https://community.servicenow.com/community?id=community_blog&sys_id=18ac2225dbd0dbc01dcaf3231f9619e3

This is what I am referencing. 

 

I am trying to gather more information on how to use it. Does this work with onLoad Catalog client scripts?

 

function onLoad() {

var ga = new GlideAjax('u_pcClientScriptIncl');
ga.addParam('sysparm_name', 'getProdType');
ga.addParam('sysparm_user', g_user.userID);
//ga.addParam('sysparm_user', currentUser.userID);
ga.getXML(getProductTypes);
var gb = new GlideAjax('u_pcClientScriptIncl');
gb.addParam('sysparm_name', 'getLocalization');
gb.addParam('sysparm_user', g_user.userID);
//ga.addParam('sysparm_user', currentUser.userID);
gb.getXML(processLocalizations);

}

 

function getProductTypes(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON();
for( var i=0 ; i < answer.length ; i++) { //Loop into the array
   g_form.addOption('ProdTypeVar', answer[i], answer[i]);
  }
}


function processLocalizations(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = answer.evalJSON();
for( var i=0 ; i < answer.length ; i++) { //Loop into the array
   g_form.addOption('Localization', answer[i], answer[i]);
  }
}

 

Here is my onload scrip that I am trying to use in the service portal I have tried instantiating the glideUserSession function in this but it is not seeming to work. Anyone have any ideas? The 2 current.user sections I commented out when testing the 

function(glideUserSession) {

      /* widget controller */

    var c = this;

      //glideUserSession provided OOTB used to like g_user

      glideUserSession.loadCurrentUser().then(function(currentUser) {

calls. 

 

1 REPLY 1

benjamin_alldri
Mega Expert

Catalog Client Scripts function a similar way to a normal Client Script, so you should be able to use g_user. glideUserSession is for development within widgets and portal pages where you're directly working with the Angular controllers.