how to get the session id of user using java script in servicenow to use in the UI button

manojlakshmanas
Kilo Expert

i need to get the current user session ID by button in the computer table

1 ACCEPTED SOLUTION

James_Neale
Mega Guru

// global scope returns Java String


// app scopes return JavaScript String


gs.getSessionID();



// OR



// global scope only - Java String


gs.getSession().getSessionID();



To show this in the UI to a user:



Display business rule:


g_scratchpad.user_session_id = gs.getSessionID();



UI Action - Client


alert('Your session ID is: ' + g_scratchpad.user_session_id || 'Unknown');


View solution in original post

8 REPLIES 8

srinivasthelu
Tera Guru

Hi Manoj,



Below thread may help you.



GlideSession - ServiceNow Wiki


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Manoj,



Here you go.


gs.info(gs.getSession()); //Accesses the GlideSession Session ID.


Please check section 5.14 for more info here.


GlideSystem - ServiceNow Wiki



Please elaborate your question further in case this doesn't answer your question.


By pressing a button in computer form i need to show the session ID of the current user in alert message.


i need to access the session ID in client side script,.


didn't the answer from Pradeep help you out?