Mark Roethof
Tera Patron
Tera Patron

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Hi there,

 

Within HR Service Delivery you can assign HR cases automatically to agents using Matching Rules. This could end up in having HR Cases that have the same "Assigned" to and "Subject person". What if you would like to prevent this? Is there a way to prevent assigning HR cases to an agent who is the subject person?


Matching Rules

HR matching Rules use the Resource "Matching Engine" plugin that is activated with the "Human Resources Scoped App: Core" plugin. You can specify a table and a condition. For HR cases that meet these conditions, the "hr_AssignmentAPI" Script Include is called to return a list of agents that are eligible for assignment. 

 

Looking at Matching Rules and the Condition Builder, these only concern matching, not excluding. Because it is mentioned on the Product Documentation that a Script Include is called to return a list of eligible agents, we might have a look at what we can do there, to prevent assigning HR cases to an agent who is the subject person.

hr_AssignmentAPI > hr_AssignmentUtil

Opening the "hr_assignmentAPI" Script Include which is mentioned on the Product Documentation, you might quickly spot that four (4) times another Script Include is called: "hr_AssignmentUtil". Reading the "hr_AssignmentUtil" Script Include does require a bit more technical knowledge of ServiceNow.

 

Scrolling through the Script Include and its functions, you might notice that multiple times a GlideRecord query is performed on the "Group Members" [sys_user_grmember] table. That looks interesting!

One of the GlideRecord queries:

 

var groupMemberGr = new GlideRecord('sys_user_grmember');
groupMemberGr.addQuery('group', taskRecord.assignment_group);
groupMemberGr.addQuery('user.active', true);
groupMemberGr.query();

while (groupMemberGr.next())
    agents.push(groupMemberGr.getValue('user'));

return agents;

 

The GlideRecord query basically queries for active users within the group that the HR case is assigned to. To achieve what we are after, preventing assigning the HR case to an agent who is also the subject person, we could enhance the GlideRecord query with a comparison of the user not being equal to the HR case subject person. Something like below should work:

 

groupMemberGr.addQuery('user', '!=', taskRecord.subject_person);

 

Expanding the GlideRecord query, the GlideRecord query would look like:

 

var groupMemberGr = new GlideRecord('sys_user_grmember');
groupMemberGr.addQuery('group', taskRecord.assignment_group);
groupMemberGr.addQuery('user', '!=', taskRecord.subject_person);
groupMemberGr.addQuery('user.active', true);
groupMemberGr.query();

while (groupMemberGr.next())
    agents.push(groupMemberGr.getValue('user'));

return agents;

 

Note: There are three (3) GlideRecord queries on sys_user_grmember written in the script include! You need to expand all three.


Result

After having updated all three GlideRecord queries and submitting new HR cases, you will notice that none of the HR cases will be automatically assigned anymore to an agent who is also the subject person!

 

Note: A change like this, is considered to be customization!

---


And that's it actually. Hope you like it. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Platform Architect @ Eraneous

3x ServiceNow Developer MVP

3x ServiceNow Community MVP

---

LinkedIn

Version history
Last update:
‎08-03-2024 07:08 AM
Updated by:
Contributors