How to use session variable in service now

nagaklv
Tera Contributor

Hello Community,

Can anyone help us one rela time senario by using session variables in service now.

It would be helpful if any one provide code with one realtime example.

 

Thanks,

Nagesh

 

 

3 REPLIES 3

Saurav11
Kilo Patron
Kilo Patron

hello,

Below thread has a good example of use if session in Servicenow:-

https://community.servicenow.com/community?id=community_question&sys_id=1df9cb29db5cdbc01dcaf3231f96196e

Please mark answer correct/helpful based on Impact.

Maik Skoddow
Tera Patron
Tera Patron

Hi @nagaklv@gmail 

you can store values in the session for any caching purposes. For example, after users logs in you could store the user's company name in the session and reuse it in any user criteria. That way, the time-consuming loading of the user properties can be prevented.

Store a value in the session object

var session = gs.getSession();

session.putClientData('<KEY>', '<VALUE>');

 

Load a value from the session object:

var session = gs.getSession();

var strValue = session.getClientData('<KEY>');

 

Let me know if you have any further questions.

Kind regards
Maik

Hi @nagaklv@gmail 


In case you think I was able to answer your question, I would be happy if you mark the appropriate response as "correct" so that the question will appear as resolved for other users who may have a similar question in the future.

If not, please tell me what you are still missing.

Many thanks & kind regards
Maik