The Zurich release has arrived! Interested in new features and functionalities? Click here for more

API for HR Condition that drives user criteria

shelbyadams
Tera Contributor

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?

1 REPLY 1

M Iftikhar
Mega Sage

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.

MIftikhar_0-1758804720470.png

The script include definition I am referring to:

MIftikhar_1-1758804763669.png

HR Criteria table ( I passed US Users ID to function):

MIftikhar_2-1758804804311.png

HR Condition Table:

MIftikhar_3-1758804925055.png

 

Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.