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
‎01-07-2016 04:38 AM
Hi,
are you accessing Session data on Client side right? it will not work on server side code.
and it is same in geneva as per Docs. Session client data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2016 04:59 AM
Yes we did, we are trying to get it to work in our ESS portal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2016 05:37 AM
Update: it does work in for instance a 'Client Script' of the incidents table, it seems like something is maybe resetting the session in our custom ESS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-22-2016 09:10 AM
I have a similar issue too - which is odd and is on a session.established Event Script Action
i was looking at something and trying to understand why it was not working, so I thought I'd add a quick Client Script to sanity check. It returned "undefined"
I have check the Script Action, I have created a second Script Action that runs and confirms the value is set
I have a Client Script that just returns "undefined" and a BR that just shows null.
Script Action 1 (order 1)
setData();
function setData() {
gs.getSession().putClientData("vs", "value1");
gs.log('set vs client data : ' + gs.getSession().getClientData("vs"));
}
Script Action 2 (order 100)
readData();
function readData() {
gs.log('set vs client data 2 : ' + gs.getSession().getClientData("vs"));
}
BR
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
gs.log('checking client data : ' + gs.getSession().getClientData("vs"));
}
CS
function onLoad() {
alert('boo1');
var v = g_user.getClientData('vs');
alert('boo2 : ' + v );
alert('boo3 :' + g_user.getClientData("vs"));
//Type appropriate comment here, and begin script below
}
From the log file
So you can see the two Event Script Actions run, and the 2nd one indicates it is all good as it has read the value set from the first Script Action
the BR shows blank - the line in the BR was a copy from the Event Action.
The CS shows "undefined"
Thing is our main instance uses some with no problems at all, but I am using this for some new developement.
And this code is on a Fuji developer instance, freshly grabbed with no updates