Save preference business rules
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 06:33 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 06:44 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2025 11:54 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2025 03:49 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader