Query using join, having, count, etc
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2024 08:15 PM
I want to create a query : select top 10 users(User table) with more that 1 position (Job table).
I am doing this but seems like is not working, any ideas where this is failing?
var grEmployees = new GlideRecord('sys_user');
var grPositions = grEmployees.addJoinQuery('sn_hr_core_job', 'user', 'user');
grPositions.addAggregate('COUNT', 'user');
grPositions.addHaving('COUNT', '>', 1);
grPositions.orderBy('name');
grEmployees.query();
var count = 0;
while (grEmployees.next() && count < 10) {
gs.info('Employee ID: ' + grEmployees.name + ', Name: ' + grEmployees.email);
count++;
}
0 REPLIES 0