- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 02:48 AM
Hello, all. This script is meant to produce a list of active users but skipped ~1,500. What am I doing wrong?
Thank you in advance!
-Tim
var users = new GlideRecord('sys_user');
users.addQuery('active', true); //Active users only
users.query();
while (users.next()) {
users.next();
gs.info(users.user_name);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 03:02 AM
Hello @timnardoni ,
You're using the "next()" method twice per loop. That's why every second user is skipped.
Please remove the second one, so that it looks like this:
var users = new GlideRecord('sys_user');
users.addQuery('active', true); //Active users only
users.query();
while (users.next()) {
gs.info(users.user_name);
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 02:57 AM
Hello @timnardoni , can you please try following:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 02:58 AM - edited 05-28-2025 03:11 AM
did you print the row count?
Try this and skip the query business rule and see what count it gives
var users = new GlideRecord('sys_user');
users.addActiveQuery(); //Active users only
users.setWorkflow(false); // skip query business rule
users.query();
gs.info('row count' + users.getRowCount());
while (users.next()) {
gs.info(users.user_name);
}
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
05-28-2025 03:02 AM
Hello @timnardoni ,
You're using the "next()" method twice per loop. That's why every second user is skipped.
Please remove the second one, so that it looks like this:
var users = new GlideRecord('sys_user');
users.addQuery('active', true); //Active users only
users.query();
while (users.next()) {
gs.info(users.user_name);
}
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2025 05:50 AM
Perfect, thank you, @Robert H and @Nishant8!
@Ankur Bawiskar, that row count trick is a good; I will use it again! 😁