Help with User Criteria Advanced Script

jlaue
Mega Sage

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!!

 

 

1 ACCEPTED SOLUTION

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;
}

View solution in original post

9 REPLIES 9

SanjivMeher
Mega Patron

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;
}

 

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!

 

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;
}

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.