Help with User Criteria Advanced Script

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

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

9 REPLIES 9

Hi Winston,

can you provide your script and how you used "user_id"?

thanks!

Hello, 

This should be it:

checkCondition();

function checkCondition() {
var user = new GlideRecord('sys_user');
user.get(user_id);

if(user.u_custom_field == true) {
return true;
}
return false;
}

Per the documentation:

 

  • Do not use gs.getUser() or other session APIs since they cause conflict when used in diagnostic tools. Use the pre-defined user_id variable available in the script to get the user id of the user being used to evaluate the script.

jlaue
Kilo Sage

That worked!  Thank you!!

Shaziya Sayed
Tera Contributor

Hello - I am working on a User Criteria requirement. 
Can anyone help me with the script part.
Requirement is :
Catalog items are classified based on IT and Non-IT Services.
A new User Criteria record for IT Service-related catalog items will be created with below condition –
User’s Department= ”IT” OR  
Parent Department of User Department’s = ”IT” OR 
User’s Manager Department= ”IT”