Issue with gs.getUser().getPreference() method in User table

Bhagya Lakshmi
Mega Guru

Hello Team,

I am getting an error while setting a filter condition on the User table from a scoped application.

Condition: sys_id is javascript: gs.getUser().getPreference('user.id');

Error: Illegal access to method getPreference(string) in class com.glide.sys.User

I have tried gs.info(gs.getUser().getPreference('user.id')) in background script. There I am getting value without error.

Why this error is coming only in User table? What is other solution for this?

Thanks in advance.

3 REPLIES 3

Mike Patel
Tera Sage

Please refer to http://www.john-james-andersen.com/blog/service-now/servicenow-user-preferences-server-client-access.html

you will have to do something like

//Set a User Preference
var user = gs.getUser().getUserByID("a2826bf03710200044e0bfc8bcbe5ded");

//Get the value for a specific User's User Preference
var prefVal = user.getPreference("DESIRED_PREFERENCE_NAME");

Hello Mike,

I have tried that example in the background scripts in a scoped application. I'm getting warnings in logs, like this

Cannot find function getUserByID in object com.glide.script.fencing.ScopedUser@1b9c6a8.

Can we use getUserByID() in scoped applications?Otherwise, what is the alternate solution?

Alternate will be create script includes and call that from your scoped app.