User Language: User Preference vs User Profile

jamesmcwhinney
Giga Guru

Our end users will be primarily accessing our servicenow instance via our ESS portal.

On the ESS portal, there is a "My Profile" section which allows the user to change their language.

Initially, this works fine.

When happens next is that at some point a user finds them self on the main portal.   Once on the main portal, the user then changes their language via the gear icon which creates a personal preference which now overrides the language in the "My Profile" area, rendering it meaningless.

What is the best way to prevent this, and ensure a consistent language setting via both ESS and the main portal?

Thanks,

- James

1 ACCEPTED SOLUTION

jamesmcwhinney
Giga Guru

Please disregard the earlier questions, I ended up fixing this via 1 business rule against the sys_user_preference table that will update the user's profile and cancel the attempt to create the user preference:




Name: Sync User Profile Language


Table: User Preference [sys_user_preference]


Advanced: yes


When: before


Insert: Yes


Update: Yes


Filter Conditions: When Name is "user.language"


Script:


function onBefore(current, previous) {


    //Update the user's profile and block the creation of a user preference


  gr = new GlideRecord('sys_user');


  gr.addQuery('user_name',current.user.user_name);


  gr.query();


  while (gr.next()) {


  gr.preferred_language = current.value;


  gr.update();


  }


  current.setAbortAction(true);


}


View solution in original post

6 REPLIES 6

epam
Kilo Guru

Hello James,



One solution would be to move language picker to the top of portal page (something like this):


language_picker.png


And remove language field from ess view of sys_user form.


That way, the language selector will be always accessible and only in one place.



Hope that helps


Thanks epam,


That looks like just what we need.



Would you be able to offer any guidance on how would I go about creating a custom language picker in the portal header account menu?



Thanks,


- James


jamesmcwhinney
Giga Guru

I am trying the business rule approach for now until I find something better.


1: create a business rule against user preference to update profile record


2: create a business rule against user profile to clear out preference record




Here is what I have for the first business rule (against the user preference table to update the associated user's profile):


businessRule.JPG


For some reason this isn't working.


Any suggestions?


Thanks!


- James


jamesmcwhinney
Giga Guru

Please disregard the earlier questions, I ended up fixing this via 1 business rule against the sys_user_preference table that will update the user's profile and cancel the attempt to create the user preference:




Name: Sync User Profile Language


Table: User Preference [sys_user_preference]


Advanced: yes


When: before


Insert: Yes


Update: Yes


Filter Conditions: When Name is "user.language"


Script:


function onBefore(current, previous) {


    //Update the user's profile and block the creation of a user preference


  gr = new GlideRecord('sys_user');


  gr.addQuery('user_name',current.user.user_name);


  gr.query();


  while (gr.next()) {


  gr.preferred_language = current.value;


  gr.update();


  }


  current.setAbortAction(true);


}