User criteria for HR case

Hafsa1
Mega Sage

I need to have a user criteria in "Available for" section of record producer.

criteria is - if any user belong to 2 groups (A and B) and have "HR Team" in his HR profile's "Job code" field, then only this record producer should be visible.

how to match both condition as these are in 2 different tables?

1 ACCEPTED SOLUTION

Bhavya11
Kilo Patron

Hi @Hafsa1 

To achieve this, you can create a custom script in the User Criteria to evaluate whether the user belongs to the specified groups and has the "HR Team" in their HR profile's "Job code" field. Here's a step-by-step guide to help you set it up:

Create new user Criteria:

advance should be true:

 

 

var userSysId = user_id;

// Initialize variables to store group membership status and HR Job Code status
var isInGroupA = false;
var isInGroupB = false;
var hasHRJobCode = false;

// Check if the user belongs to Group A
var groupA = new GlideRecord('sys_user_grmember');
groupA.addQuery('user', userSysId);
groupA.addQuery('group.name', 'Group A');
groupA.query();
if (groupA.next()) {
    isInGroupA = true;
}

// Check if the user belongs to Group B
var groupB = new GlideRecord('sys_user_grmember');
groupB.addQuery('user', userSysId);
groupB.addQuery('group.name', 'Group B');
groupB.query();
if (groupB.next()) {
    isInGroupB = true;
}

// Check if the user has "HR Team" in the Job Code field in their HR profile
var hrProfile = new GlideRecord('sn_hr_core_profile');
hrProfile.addQuery('user', userSysId);
hrProfile.addQuery('job_code', 'HR Team');
hrProfile.query();
if (hrProfile.next()) {
    hasHRJobCode = true;
}

// Return true only if all conditions are met
if (isInGroupA && isInGroupB && hasHRJobCode) {
    answer = true;
} else {
    answer = false;
}

 

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

 

 

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Hafsa1 You need to use Advanced criteria with script here. In the script you need to validate if the current user is part of both the groups and make a GlideRecord query to HR Profile to check their job code. Based on the evaluation of both these conditions in the script, you can either return true or false.

 

Screenshot 2024-07-24 at 3.49.51 PM.png

Bhavya11
Kilo Patron

Hi @Hafsa1 

To achieve this, you can create a custom script in the User Criteria to evaluate whether the user belongs to the specified groups and has the "HR Team" in their HR profile's "Job code" field. Here's a step-by-step guide to help you set it up:

Create new user Criteria:

advance should be true:

 

 

var userSysId = user_id;

// Initialize variables to store group membership status and HR Job Code status
var isInGroupA = false;
var isInGroupB = false;
var hasHRJobCode = false;

// Check if the user belongs to Group A
var groupA = new GlideRecord('sys_user_grmember');
groupA.addQuery('user', userSysId);
groupA.addQuery('group.name', 'Group A');
groupA.query();
if (groupA.next()) {
    isInGroupA = true;
}

// Check if the user belongs to Group B
var groupB = new GlideRecord('sys_user_grmember');
groupB.addQuery('user', userSysId);
groupB.addQuery('group.name', 'Group B');
groupB.query();
if (groupB.next()) {
    isInGroupB = true;
}

// Check if the user has "HR Team" in the Job Code field in their HR profile
var hrProfile = new GlideRecord('sn_hr_core_profile');
hrProfile.addQuery('user', userSysId);
hrProfile.addQuery('job_code', 'HR Team');
hrProfile.query();
if (hrProfile.next()) {
    hasHRJobCode = true;
}

// Return true only if all conditions are met
if (isInGroupA && isInGroupB && hasHRJobCode) {
    answer = true;
} else {
    answer = false;
}

 

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

 

 

@Bhavya11 Never ever use 

gs.getUserID();

In a user criteria script, instead use user_id against whom the evaluation is happening.

Hafsa1
Mega Sage
Thanks @Bhavya11  its working.