- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2019 01:23 PM
Hello!
I wrote a script include to user as a reference qualifier in a reference variable. The script works as intended, the problem is it is very slow so I'm thinking there must be something wrong. The else statement works great and loads the reference variable quick. However the if statement in bold (when the logged in user has the role) the reference variable will take almost 2 minutes to load the users. I know querying all active users is a lot, however before adding this reference qualifier, if the simple condition builder was just set to active is true it loaded quickly.
Please let me know if you have any tips for the script below:
var NHL_new_hire_user = Class.create();
NHL_new_hire_user.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNewHires: function() {
var user = [];
var current_user = gs.getUserID();
var roles = new GlideRecord('sys_user_has_role'); //query what roles the current user has and look for nhl role
roles.addQuery('user', current_user);
roles.addQuery('role', 'df97b1dcdbd0670092773220ad96196b'); //nhl_admin role
roles.query();
if (roles.next()){ //if the logged in user does have the nhl role
var all_users = new GlideRecord('sys_user'); //query all active users
all_users.addQuery('active', true);
all_users.query();
while(all_users.next()){
user.push(all_users.sys_id.toString()); //push an array of all active users
}
}
else{ //logged in user does not have nhl role
var user_manager = new GlideRecord('sys_user'); //querying active users whose manager is the logged in user
user_manager.addQuery('active',true);
user_manager.addQuery('manager', current_user);
user_manager.addQuery('u_contractor', false);
user_manager.query();
while(user_manager.next()){
user.push(user_manager.sys_id.toString()); //push an array of active users with logged user as manager
}
}
return 'sys_idIN' + user.join(',');
},
type: 'NHL_new_hire_user'
});
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2019 02:50 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2019 02:10 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2019 02:17 PM
Thanks Jon. It is not working...all active users are still showing up even if I don't have the nhl_requisition_admin role. I did verify this is the name of the role and tried doing the sys_id too.
This is what the full script include looks like now:
var NHL_new_hire_user = Class.create();
NHL_new_hire_user.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getNewHires: function() {
var ret = ('active=true');
if (!gs.hasRole('nhl_requisition_admin')) {
ret += '^u_contractor=false^manager=javascript.gs.getUserID()';
}
return ret;
},
type: 'NHL_new_hire_user'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2019 02:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2019 02:28 PM
Ohh okay, that makes sense. Let me try impersonating someone without admin and without the role and see if it works. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2019 02:37 PM
Ok so users with the role can see all active users. But users without the role see no users