Reference Qualifier: Filter Users by Department, Specific Roles & Recent Login (Last 30 Days)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2025 11:32 AM
Hey Community!
I just completed an advanced reference qualifier scenario and wanted to share it for learning and feedback.
Goal:
Show only those users in a reference field who:
Belong to the same department as the currently logged-in user.
Have either the "ITIL" or "approver escalation" role.
Logged in within the last 30 days.
Use Case:
Useful for restricting approvals, escalations, or assignments to only active and relevant users in the same department.
Script Include Used:
var refrence_Qulifer_Advance_level_task_04 = Class.create();
refrence_Qulifer_Advance_level_task_04.prototype = Object.extendsObject(AbstractAjaxProcessor, {
advancelevel: function() {
var gr = new GlideRecord('sys_user');
var userDepartment;
if (gr.get(gs.getUserID())) {
userDepartment = gr.department.sys_id;
}
// return 'department='+userDepartment;
var hasRoles = [];
var checkrole = new GlideRecord('sys_user');
checkrole.addActiveQuery();
checkrole.addEncodedQuery('roles=itil^roles=approver_escalation');
checkrole.addEncodedQuery('last_loginONLast 30 days@javascript:gs.beginningOfLast30Days()@javascript:gs.endOfLast30Days()');
checkrole.query();
while (checkrole.next()) {
hasRoles.push(checkrole.sys_id.toString());
}
// return days;
return 'sys_idIN' + hasRoles + '^department=' + userDepartment;
// return 'sys_idIN' + hasRoles;
},
type: 'refrence_Qulifer_Advance_level_task_04'
});
0 REPLIES 0