Lubos Strejcek

Aug 3, 2022

Refreshing session in SN without logout

Very common business requirement is to update users roles dynamically without asking them to re-login and also profile pictures.

This problem is pending the fix related to PRB1360299/KB0951799 because the photo ref which is being used to get the image from the cache will now get deleted. Just run a following code in the background script, this is a kinf of usefull feature for developers.

Refresh roles without forced log-out

GlideSecurityManager.get().setUser(gs.getUser());

Refresh GlideUser session cache

gs.getSession().loadUserByID(gs.getUser().getID());

GlideRollback usage

var rollback = new GlideRollback();
 
var modCount = 0;
 

 
var sys_user = new GlideRecord('sys_user');
 

 
var userId = "--put the sysId here--";
 
if (sys_user.get(userId )) {
 
modCount = parseInt(sys_user.sys_mod_count.toString(), 10);
 

 
rollback.toVersion(sys_user, modCount - 1);
 
gs.info(sys_user.last_name.toString());
 

 
rollback.toVersion(sys_user, modCount - 2);
 
gs.info(sys_user.last_name.toString());
 
}