We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

setPreference Method

Anil74
Tera Guru

Hi All,

Anyone can explain about setPreference method.

Thank you.

3 REPLIES 3

Arnoud Kooi
ServiceNow Employee

It's a serverside method and will insert or update a user preference in the sys_user_preference table.


Usage example:



gs.getUser().setPreference('name', 'value');


Deepak Ingale1
Mega Sage

In addition to what Arnoud has method, there is setPreference method for GlideDialogWindow API



https://www.servicenowguru.com/system-ui/glidedialogwindow-advanced-popups-ui-pages/


Slava Savitsky
Giga Sage

The purpose of setPreference method is to save a user-specific setting in the User Preferences table. In server-side scripts, use the following syntax to set a preference for the current user:

gs.getUser().setPreference('user_preference_name', 'user_preference_value');

In client-side scripts, use this instead:

setPreference('user_preference_name', 'user_preference_value');

For more information about User Preferences, refer to this article from the product documentation.