
ServiceNow can serve up a user’s personal preferences either with server-side API access or client-side function calls. Get it your way.
You may already be aware of this, but ServiceNow has the capability to set and retrieve user preferences within the platform. You can easily get or set these preferences using both server-side APIs as well as client-side APIs. This article will explain how you can do this both at the server level and at the client level.
API Functions
Server Side API Calls
Since user preferences are tied to and individual user, the server-side API gets you access to those user preferences at the gs user level. To access these APIs on the current user simply use the following method:
1 2 3 4 | //Set your current User Preference gs.getUser().setPreference("DESIRED_PREFERENCE_NAME", "DESIRED_PREFERENCE_VALUE"); //Get your user's current User Preference Value var prefVal = gs.getUser().getPreference("PREFERENCE_NAME"); |
To get the API on another user using a Server Side script, you would do the following:
1 2 3 4 5 6 | //Set a User Preference var user = gs.getUser().getUserByID("a2826bf03710200044e0bfc8bcbe5ded"); user.setPreference("DESIRED_PREFERENCE_NAME", "DESIRED_PREFERENCE_VALUE"); //Get the value for a specific User's User Preference var prefVal = user.getPreference("DESIRED_PREFERENCE_NAME"); |
Client Side API Calls
You can also allow your client scripts to access the current user’s user preferences in the following way:
1 2 3 4 5 | //Set your current user preference setPreference("DESIRED_PREFERENCE_NAME", "DESIRED_PREFERENCE_VALUE"); //Get your current user's preference getPreference("DESIRED_PREFERENCE_NAME"); |
Viewing the user preferences manually
You can also view and manage all user preferences as the system administrator. Simply navigate to User Administration > User Preferences.
Demo Video
The post ServiceNow User Preferences – Server and Client Access appeared first on John Andersen.