User Criteria script by Company and Employee Type

Bret Smith
Giga Guru

Trying to develop a user criteria for users with OIT company AND u_employee_type = Full Time/Staff

 

 
checkCondition();

function checkCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.u_employee_type=='Full Time/Staff')
{
     return true;
}
return false;
}
 
BretSmith_0-1717694017475.png

 

 

I am impersonating a user who is an OIT AND Employee Type is Vendor and the user can stil see the catalog item.

BretSmith_1-1717694697849.png

 

 
 
 
3 REPLIES 3

Zach Koch
Giga Sage
Giga Sage

Here is a link to the documentation, and here a screenshot to the relevant portion. Best practice is not to use any Session APIs and instead use the provided user_id variable. Hopefully this helps solve your issue.

ZachKoch_0-1717697483139.png

User critera docs 

If this information helped resolve your issue, please remember to mark response correct and thumbs up to help future community members on this information, thanks!

dhanrajb
Tera Guru

Hi,

 

There are some restrictions with user criteria. Try the below code,

 

 

var userId = gs.user_id();
var user = new GlideRecord('sys_user');
user.get(userId);
if (user.u_employee_type == 'Full Time/Staff') {
	answer = true;
} else {
	answer = false;
}

 

 

Regards,

Dhanraj.

Bret Smith
Giga Guru

Here is what I have found to work 

 

1. Remember to log out and back in when testing changes to advanced User Criteria scripts

2. This script worked
answer = checkCondition();

function checkCondition(){
var user = new GlideRecord('sys_user');
user.get(gs.getUserID());
if (user.u_employee_type=='Full Time/Staff' && user.company=='OIT')
{
return true;
}
return false;
}


3. And this script worked
answer = checkCondition();

function checkCondition() {

var user = new GlideRecord('sys_user');
user.get(gs.getUserID());

var emp_type = user.u_employee_type;
var emp_company = user.company;

if(emp_type == 'Full Time/Staff' && emp_company == 'OIT')
return true;
else
return false;
}