User Criteria on catalog item

Ram050670
Tera Guru

Hi All,

i am looking for a User criteria on catalog item that will be available for only Employee type Employee and active True. 
how to filter the users with employee type? 

usually we add groups and role on the available for but in this case we need Employee type Employee and active user.

2 ACCEPTED SOLUTIONS

Ashir Waheed
Kilo Sage
Kilo Sage

Hi @Ram050670 

 

You will need to create a New User Criteria (user_criteria) record

  1. In the Application navigator, Navigate to the Service Catalog->Catalog Definition->User Criteria
  2. Check the Advanced check box.
  3. AshirWaheed_1-1708461220215.png
  4. Write the script as you return the desired filter user.
  5. AshirWaheed_0-1708462342835.png
  6. Save the Record.
  7. Go to your catalog item in the Available for related list and Edit the list and enter the user criteria you created.
    AshirWaheed_2-1708461530567.png

     

Script:

var user = new GlideRecord("sys_user");
//Change filter according to yours variable names
user.addEncodedQuery("employee_typeSTARTSWITHEmployee^active=true");
user.query();
while(user.next()){
answer=true;
}

 

This will resolve your requirement.

 

Regards,

Ashir Waheed

 

View solution in original post

tried this it worked for me: 

 

 
var EmpType = gs.getUser().getRecord().getDisplayValue('u_employee_type');

if (EmpType == 'Employee') {
    condition = true;
} else {
    condition = false;
}

View solution in original post

7 REPLIES 7

Saloni Suthar
Mega Sage
Mega Sage

Hi @Ram050670 ,

You have to write a script in the User Criteria:

 

 

checkCondition();

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

if(user.<<custom field name> == 'value of the employee choice') {
return true;
}
return false;
}

 

 

If my response helped you, please mark it as correct or helpful.

 


If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni

i tried the above script but it didnt work for me, i used this  below script and it worked.
 
 
 
var EmpType = gs.getUser().getRecord().getDisplayValue('u_employee_type');

if (EmpType == 'Employee') {
    condition = true;
} else {
    condition = false;
}

jcmings
Mega Sage

You'll need to call this function in your user criteria record:

new sn_hr_core.hr_Criteria().evaluateById("sys_id_of_HR_criteria_record", user_id);

 Then, create a record in the HR Criteria table. (You'll pass the sys_id of this HR Criteria record into the above function.) Within that HR Criteria record, create a HR Condition on the table HR Profile. Make sure your User column is set to User.

Ashir Waheed
Kilo Sage
Kilo Sage

Hi @Ram050670 

 

You will need to create a New User Criteria (user_criteria) record

  1. In the Application navigator, Navigate to the Service Catalog->Catalog Definition->User Criteria
  2. Check the Advanced check box.
  3. AshirWaheed_1-1708461220215.png
  4. Write the script as you return the desired filter user.
  5. AshirWaheed_0-1708462342835.png
  6. Save the Record.
  7. Go to your catalog item in the Available for related list and Edit the list and enter the user criteria you created.
    AshirWaheed_2-1708461530567.png

     

Script:

var user = new GlideRecord("sys_user");
//Change filter according to yours variable names
user.addEncodedQuery("employee_typeSTARTSWITHEmployee^active=true");
user.query();
while(user.next()){
answer=true;
}

 

This will resolve your requirement.

 

Regards,

Ashir Waheed