API for HR Condition that drives user criteria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
We’re building an internal Enterprise Search AI tool from scratch that indexes Knowledge Base articles via the ServiceNow API. To enforce Knowledge access, we need to respect the User Criteria on each article.
The API lets us pull the User Criteria sys_id, but it doesn’t give us the resolved list of users who actually match that criteria.
In our environment, many of these User Criteria reference HR Criteria, and the HR Criteria itself is driven by an HR Condition. The HR Condition dynamically filters the HR Profile table to determine the final set of users.
This is the logic we need to follow/map:
Knowledge Article → User Criteria → HR Criteria → HR Condition → User list (from HR Profiles)
Has anyone found a supported way (API, or other approach) to:
Call the HR Criteria → resolve its HR Condition → return the resulting user list, or
Access an API endpoint that directly returns the list of users who satisfy a given User Criteria?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @shelbyadams ,
Create a custom REST endpoint and call this OOTB script include, pass in the sys_id and receive JSON list of user sys_ids (or some user attributes).
Check below code, I called it with in a fix script in HR Core scope for demo.
var hrCritId = '07bcc228530222005d5ba5f4a11c086f'
var usersList = new sn_hr_core.hr_Criteria().getUsersForHRCriteria(hrCritId, false);
gs.info(usersList);
var result = [];
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', 'IN', usersList.join(','));
gr.query();
while (gr.next()) {
result.push({
sys_id: gr.sys_id.toString(),
name: gr.getDisplayValue('name'),
email: gr.getValue('email')
});
}
gs.info(JSON.stringify(result));
Result in Logs.
The script include definition I am referring to:
HR Criteria table ( I passed US Users ID to function):
HR Condition Table:
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.