- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:01 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:22 AM - edited 07-24-2024 03:49 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:22 AM
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:22 AM - edited 07-24-2024 03:49 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 03:30 AM
@Bhavya11 Never ever use
gs.getUserID();
In a user criteria script, instead use user_id against whom the evaluation is happening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2024 07:47 PM - edited 07-24-2024 09:03 PM