- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:39 AM
Hello experts,
I'm trying to hide a catalog item for specific users, based on sys_user string field.
I've created not available for user criteria with a simple script, but for some reason it doesn't work (relevant user are still able to see - even after cleaning cache and log out login).
I've found some articles about the gs.getUser issues within the user criteria advance script. that suggest to use extend user criteria but my field is string and not a reference.
my script:
answer();
function answer() {
var user_id = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.get(user_id);
var userSource = gr.getValue('state');
if (userSource == "SW") {
return true;
} else {
return false;
}
}
Did someone find a solution for this issue?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 01:52 AM
did you debug it by adding gs.info()?
I hope the field name state is correct, since state field is not present OOB
Also update script as this. The answer variable needs to be set with true/false
If user's state value is SW it won't be available for
answer = checkUserRecord();
function checkUserRecord() {
var gr = new GlideRecord('sys_user');
if(gr.get(user_id)){
var userSource = gr.getValue('state');
if (userSource == "SW") {
return true;
} else {
return false;
}
}
}
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
03-21-2023 01:52 AM
did you debug it by adding gs.info()?
I hope the field name state is correct, since state field is not present OOB
Also update script as this. The answer variable needs to be set with true/false
If user's state value is SW it won't be available for
answer = checkUserRecord();
function checkUserRecord() {
var gr = new GlideRecord('sys_user');
if(gr.get(user_id)){
var userSource = gr.getValue('state');
if (userSource == "SW") {
return true;
} else {
return false;
}
}
}
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
03-21-2023 08:21 AM
Thank you Ankur & Prince!