advance reference qualifier returning slow results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 01:54 PM
My requirement is on incident caller field, only those users should show that are active, employee number is not null and employee number is numeric. I am using this script include and calling it in my ref qual. But when I type in few letters in caller field, it takes forever to bring the results. Example, if I type Aar, it takes about 10 seconds to load Aaron.
Script include -
getActiveNumericEmployeeUsers: function() {
var usersList = [];
var gr = new GlideRecord('sys_user');
// Properly filtering active users and ensuring employee_number is not null
gr.addQuery('active', true);
gr.addNotNullQuery('employee_number');
gr.query();
var regexp = /^[0-9]+$/; // Regex to check if employee_number is fully numeric
while (gr.next()) {
var employeeNumber = gr.getValue('employee_number');
if (employeeNumber && regexp.test(employeeNumber)) {
usersList.push(gr.getUniqueValue());
}
}
return usersList; // Returns an array of sys_ids
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2025 03:29 PM
Could you add some logs of the result before returning. I have just run the following function in scripts - background
function getActiveNumericEmployeeUsers() {
var usersList = [];
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('active=true^employee_numberISNOTEMPTY');
gr.query();
while (gr.next()) {
var employeeNumber = gr.employee_number;
if (!isNaN(employeeNumber)) {
usersList.push(gr.sys_id);
}
}
return "sys_idIN" + usersList;
}
gs.info(getActiveNumericEmployeeUsers());And I got the following:
sys_idINfe82abf03710200044e0bfc8bcbe5d21,fe82abf03710200044e0bfc8bcbe5d21
and I have exactly 2 users with numeric employee number. Please run the function in Scripts - background and share the results.
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
