Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to store an object or value in a session level variable in ServiceNow?

dev115415
Tera Expert

Hello

I want to store a variable in session level in ServiceNow script include. Actually I want to assign some value to a variable in one script include and access it in another script include. How to do this

1 ACCEPTED SOLUTION

Anurag Tripathi
Mega Patron
Mega Patron

Set Valye in session Variable

gs.getSession().putClientData('myData', 'Hello, world!'); 

 

Read Value

alert(g_user.getClientData('myData')); 
-Anurag

View solution in original post

3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

Set Valye in session Variable

gs.getSession().putClientData('myData', 'Hello, world!'); 

 

Read Value

alert(g_user.getClientData('myData')); 
-Anurag

can we use 

alert(g_user.getClientData('myData'));  

in different script include?

No, g_user is a client side object.

 

 

Try this in a script include 

gs.getSession().getClientData('myData')

 

-Anurag