The CreatorCon Call for Content is officially open! Get started here.

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

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');


find_real_file.png



i have added a button in the UI action and also i have added method in it i need to is display session ID to user once he clicks the button.But i get no response when i hit the button.


Hi Manoj,



gs is not available client side. As @James   showed you need to create a display business rule and pass the required value to client with the help of scratchpad.




That Business would look like,



Screen Shot 2016-02-13 at 2.36.00 PM.png



And then you can access the session id in the UI action something like this,


Screen Shot 2016-02-13 at 2.36.58 PM.png





Hope this helps


Srini


PS: Hit like, Helpful or Correct depending on the impact of the response


Thanks Srinivas Thelu I got the output