Destroy session

moncef
Tera Contributor

Hi,

How can i destroy session with scripting in Service Portal.

Thanks.

6 REPLIES 6

Gaurav Bajaj
Kilo Sage

Hi,

What you can do is make a Gliderecord query to v_user_session table, pick the logged in/whichever user and then set the locked field value to true.

This way, you can terminate the session through the script. Let me know if you need help with the script.

find_real_file.png

Please mark it correct/helpful based on the response.

Thanks
Gaurav

Hi,

I need some help in script.

This is what i do on server side script :

var username = gs.getUserName();
var ses = new GlideRecord('v_user_session');
ses.get('user',username);

data.ses = ses.locked;

And i want to use the data.ses in client script to set the value of locked to true.

 

Thanks.

Hi,

With your script, you can get the current user locked status which would obviously be false is the user is logged in.

If you just want to display it in client script, you can use $scope.data.ses & it will give the status in client script.

 

Or if you want to set locked status at true i.e. destory the session, you can simply do in server script itself.

var username = gs.getUserName();
var ses = new GlideRecord('v_user_session');
ses.get('user',username);

ses.locked=true;

ses.update();

Please mark it correct/helpful based on the response.

Thanks
Gaurav

Hi ,

But i need to destroy session basing on a condition that i have in client script.

thanks.