Need help in Script

Mark Wood
Tera Contributor

Hello Experts,

I have written the script below, which is almost functioning correctly. However, when I print the results, duplicate values are displayed. I want to obtain unique values. 

 

var manager = [];
var users = [];
var usr = new GlideRecord('sys_user');
usr.addQuery('active',true);
usr.addQuery('sys_id','02826bf03710200044e0bfc8bcbe5d7f');
usr.query();
while(usr.next()){
users.push(usr.name.toString());
var mgr = usr.manager;
}
gs.print("First User: "+users);
manager.push(mgr);
var c=0;
var u1 = new GlideRecord('sys_user');
u1.addQuery('manager',mgr);
u1.addQuery('active',true);
u1.query();
gs.print(u1.getRowCount());
while(u1.next()){
gs.print("User Name: "+u1.name);
if(!users.includes(u1.name.toString())){
 
c++;
users.push(u1.name.toString());
 
}
}
gs.log(users);
//gs.log(c);

 

Could anyone please guide me on what mistakes I might be making? Thank you.

5 REPLIES 5

Nice! glad you could make it work. In case you need any assistance, feel free to come back to this post and mention my profile, so i will receive the notification.

Now just a quick performance tip: if you are not updating anything, consider changing from GlideRecord to GlideAggregate, it is slightly faster (although it can make a big difference when a lot of queries are running in an instance).


Have a good day!