HR Task Visiblity
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 02:14 AM
I want to restrict the visibility of HR Tasks such that only the following users can access them:
Members of the HR Case’s assignment group
Users added to the HR Case watchlist
Members of the HR Task’s assignment group
I want to achieve the before business rule can someone help me with the code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 03:42 AM
you can use query business rule on HR Task table
Something like this
Condition: gs.getSession().isInteractive()
Script:
(function executeRule(current, previous /*null when async*/ ) {
var userID = gs.getUserID();
var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
// Condition 1: User is member of HR Case's assignment group
// 'hr_case' is a reference field to the parent HR Case
var caseAssignmentGroupCondition = 'hr_case.assignment_groupIN' + groups.toString();
// Condition 2: User is on the HR Case watchlist
var caseWatchlistCondition = 'hr_case.watch_listLIKE' + userID;
// Condition 3: User is member of HR Task's assignment group
var taskAssignmentGroupCondition = 'assignment_groupIN' + group.toString() s;
// Combine conditions with OR
var condition = '(' + caseAssignmentGroupCondition + ')^OR(' +
caseWatchlistCondition + ')^OR(' + taskAssignmentGroupCondition + ')';
// Add the condition to the query
current.addEncodedQuery(condition);
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 04:03 AM
Hello @DASAMANDAMS ,
Create Query Business rule on HR Task table and add below line of code. This is works for me -
(function executeRule(current, previous /*null when async*/ ) {
if (gs.hasRole('admin') || gs.hasRole('sn_hr_core.admin')) {
return; // Allows users with these roles to view all HR Tasks without restriction.
} else {
// Assignment group is Dynamic Me OR Parent.Assignment Group is dynamic me OR parent.watchlist is dynamic me
current.addEncodedQuery('assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^ORparent.assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^ORparent.watch_listDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
}
})(current, previous);
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 04:26 AM
@DASAMANDAMS You can try the following query BR.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.addEncodedQuery('parent.assignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^ORassignment_groupDYNAMICd6435e965f510100a9ad2572f2b47744^ORparent.watch_listDYNAMIC90d1921e5f510100a9ad2572f2b477fe');
})(current, previous);