Store user information in the session
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2016 04:19 AM
Hello,
We are trying to store additional user data in the session object upon user login but to no success so far. We've followed the steps from Two ways to Reduce Client Side lookups but this does not seem to work in our (Geneva) instance. First of all, the user-related functions such as gs.getUser( ) and gs.getUserID( ) yield no results when used in the Event Script Action. We've found a way around this by using the event parameter and querying the user table ourselves, storing user info in the session however still does not work. A minimal code example of our attempted solution is:
var username = event.parm1;
var user = new GlideRecord( 'sys_user' );
user.addQuery( 'username', username );
user.query( );
gs.getSession( ).putClientData( 'test', 'TEST' );
gs.getSession( ).putClientData( 'user_company', user.company.sys_id );
The above is the script in an 'Event - Script Action' that triggers on 'session.established' (we checked this) without any conditions. According to the aforementioned tutorial this should make the variables 'test' and 'user_company' available in the front end through the calls:
g_user.getClientData( 'test' );
g_user.getClientData( 'user_company' );
but it does not. Of course, we have checked that 1) the user variable is set and 2) it has a company associated. We've included the variable 'test' with constant value 'TEST' that should show up no matter what, but even this is not included in the session on the client side (after logging in again). Are we overlooking anything in getting this to work or is this maybe functionality that has been replaced in Geneva (not mentioned in the docs)?
Thanks in advance for the help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2018 01:55 PM
I realize this is an old thread but if it helps the next person...
The issue is that script actions run asynchronously and typically aren't fully populated when trying to access them in response to events. You'll need to have the 'maint' role granted by ServiceNow and modify the ACL on the script action table to expose the attribute 'Synchronous'. I modified the role for the field ACL to include 'admin'. Add the field to your form and enable it to force your script action to run synchronously and you'll find all the information is populated.