Need help in Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 08:24 AM - edited 02-06-2024 10:01 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2024 11:18 AM - edited 02-07-2024 11:19 AM
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!