Save preference business rules

S_bastien Lavoi
Tera Contributor

Hey guys,

 

I'm trying to change a user's language upon an event being created by an external system.

 

I have the following code in a script action : 

 

var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', event.parm1);  // find user
grUser.query();

if (grUser.next()) {
	grUser.savePreference('user.language', event.parm2);
}

 

which works, but the preference does not seem to properly take effect, even if I refresh the page.  I have to log out and log back in for the new value of the preference to work.

 

Any way I can force a the new value to take effect without the user having to log out and log back in?

 

Thanks

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@S_bastien Lavoi 

that's the platform behavior. user will have to logout and login again

try this

var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', event.parm1);  // find user
grUser.query();

if (grUser.next()) {
    grUser.savePreference('user.language', event.parm2);
    gs.getSession().setLanguage(event.parm2);  // Reload the session with the new language

}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for the answer but this does not seem to work. Since this is coded in a script action and triggered by an even, I'm not sure we can use gs.getSession() as I don't want the current session, but the session of the user who's email is in parm1

@S_bastien Lavoi 

I don't think it's doable then

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader