Involved Party Classification = HR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Currently, the Involved Party Name field has limited user options. This enhancement aims to expand the selection criteria when the Involved Party Classification is set to HR.
When HR is selected as the classification:
- The dropdown should display users who are active employees.
- The users must be assigned as an HR Manager for at least one active user.
This expanded list ensures that all valid HR Managers across the organization can be selected appropriately.
For any other classification values, the existing user selection logic should remain unchanged.
how to write code for this condition in reference qual
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello @santhoshchu ,
1.To achieve this requirement in ServiceNow HRSD, you must implement a Reference Qualifier on the Involved Party Name field that dynamically filters users based on the Involved Party Classification field.The most efficient and best-practice method is using an Advanced Reference Qualifier paired with a Script Include.1. Create the Script Include. This script queries the User table (sys_user) to find active users who are set as the manager for at least one other active user, specifically filtering for HR.
Script:javascriptvar HRSDUserUtils = Class.create();
HRSDUserUtils.prototype = Object.extendsObject(AbstractScriptProcessor, {
getHRManagers: function(classification) {
// If classification is not HR, return empty to trigger default behavior
if (classification != 'HR') {
return '';
}
var managerIds = [];
// Query active users to find their managers
var grUser = new GlideRecord('sys_user');
grUser.addActiveQuery();
grUser.addNotNullQuery('manager');
grUser.query();
while (grUser.next()) {
var managerSysId = grUser.getValue('manager');
// Avoid duplicate IDs in our array
if (managerIds.indexOf(managerSysId) === -1) {
managerIds.push(managerSysId);
}
}
// Return a query string matching active users who are in the manager list
return 'active=true^sys_idIN' + managerIds.join(',');
},
type: 'HRSDUserUtils'
});
2. Configure the Reference Qualifier Next, apply this script to the Involved Party Name field configuration so it updates whenever the classification changes.Right-click the Involved Party Name field label and select Configure Dictionary.Locate the Advanced View Related Link if you do not see the reference fields.Set Use reference qualifier to Advanced.Enter the following code into the Reference qual field:
javascriptjavascript: current.involved_party_classification == 'HR' ? new global.HRSDUserUtils().getHRManagers(current.involved_party_classification) : 'active=true';
//Note: Replace involved_party_classification with the exact backend name of your classification field if it differs.
Regards ,
Supriya