We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Query using join, having, count, etc

MesihasAle
Tera Contributor

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