What is gs.getSession

Tejaswini9
Tera Expert

Hello,

What is the use of gs.getSession and where do we use it, can anyone explain me in detail as i am new to servicenow.

Regards,

Tejaswini 

1 ACCEPTED SOLUTION

Michael Jones -
Giga Sage

You can view some detailed information here

basically gs.getSession() is used in a server-side script in order to return details about the currently logged in user's session. 

Common uses are to check if the user has an interactive sessions (viewing things in the browser) using isInteractive()

Determine if the current user is impersonating someone with isImpersonating()

And to set data server-side that you can later retrieve client-side using putClientData(). 

Server-side you would normally follow something like

var session = gs.getSession()

session.putClientData('my_data_name', 'myDataValue');

You would do this in a Before business rule typically, and then client-side you would retrieve the data with

g_user.getClientData('my_data_name') which would return the string "myDataValue". 

Typically you would use this to pre-populate data from the server that you might need client-side without having to initiate a query and wait for a response.

Beyond that, you tend to learn more about sessions when you find a need to interact with them. 

If this was helpful, or correct for you, please be kind and remember to click appropriately!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

View solution in original post

3 REPLIES 3

Michael Jones -
Giga Sage

You can view some detailed information here

basically gs.getSession() is used in a server-side script in order to return details about the currently logged in user's session. 

Common uses are to check if the user has an interactive sessions (viewing things in the browser) using isInteractive()

Determine if the current user is impersonating someone with isImpersonating()

And to set data server-side that you can later retrieve client-side using putClientData(). 

Server-side you would normally follow something like

var session = gs.getSession()

session.putClientData('my_data_name', 'myDataValue');

You would do this in a Before business rule typically, and then client-side you would retrieve the data with

g_user.getClientData('my_data_name') which would return the string "myDataValue". 

Typically you would use this to pre-populate data from the server that you might need client-side without having to initiate a query and wait for a response.

Beyond that, you tend to learn more about sessions when you find a need to interact with them. 

If this was helpful, or correct for you, please be kind and remember to click appropriately!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

How do i use getClientData() in server side? I am trying 

var session = gs.getSession();
var event = session.getClientData('my_data_name');

But its not working

hello @ServiceNow SA 
To getClientdata() ... you should first putClientdata in getSession()

firstly it should run function which consists of putClientdata('my_data_name','my_data_value');// adding name and value 

then in another function we can use getClientdata() to get value.