- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2018 02:08 PM
Hello - I am working on a User Criteria requirement for a Catalog Item that I am adding. We have a custom field on the sys_user table called: u_job_code. I only want users with a specific job code to see this catalog item. This u_job_code field is not a reference field.
I was wondering how I would be able to script that in the Advanced script box of the User Criteria record for this. I would like it to filter for users where the u_jobe_code = 1000
Thanks!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2018 10:04 AM
Sorry ...Correction in code. Didnt add a space after function in previous script
checkCondition();
function checkCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.u_job_code==1000)
{
return true;
}
return false;
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2018 02:43 PM
You can do
checkCondition();
functioncheckCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.u_job_code==1000)
{
return true;
}
return false;
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2018 05:42 AM
Hello - thank you for your response. I tried to input this code and I received a few errors.
It was looking for a semicolon on line 3.
Also it has this line at the bottom:
Could not save record because of a compile error: JavaScript parse error at line (11) column (12) problem = invalid return (<refname>; line 11)
I have attached a screenshot.
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2018 10:04 AM
Sorry ...Correction in code. Didnt add a space after function in previous script
checkCondition();
function checkCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.u_job_code==1000)
{
return true;
}
return false;
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2021 10:23 AM
For people not getting consistent results when testing try clearing the system cache (by searching cache.do in the application navigator) after updating the user records...took me a while to figure out why it was sometime working and sometimes not.
I also used user_id in place of gs.getUserID() not sure that made a differents or not.