- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 08:16 AM
I have written the below code. But it is storing the same mail id in array but fetching different id in loop
var final_rec=[];
var grp_mail = new GlideRecord('sys_user_group');
var qc=grp_mail.addQuery('sys_id', 'db53580b0a0a0a6501aa37c294a2ba6b');
qc.addOrCondition('sys_id', 'db53a9290a0a0a650091abebccf833c6');
grp_mail.query();
while (grp_mail.next()) {
var mail=grp_mail.email;
gs.info(mail);
final_rec.push(mail);
}
gs.info(final_rec);
Please see the output:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 08:39 AM
My first thought is you did not account for the fact that grp_mail.email is an object that is being updated every time thru the loop. So you need to use
var mail = grp_mail.email.toString();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 08:32 AM
Hi,
You do need to check if the entry already exists before pushing into the array, please try the code below.
var final_rec = [];
var grp_mail = new GlideRecord('sys_user_group');
var qc = grp_mail.addQuery('sys_id', 'db53580b0a0a0a6501aa37c294a2ba6b');
qc.addOrCondition('sys_id', 'db53a9290a0a0a650091abebccf833c6');
grp_mail.query();
while (grp_mail.next()) {
var mail = grp_mail.email;
gs.info(mail);
if (final_rec.toString().indexOf(mail) == -1) {
final_rec.push(mail);
}
}
gs.info(final_rec);
Regards,
Ziad
Please mark reply as Helpful/Correct, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 08:39 AM
My first thought is you did not account for the fact that grp_mail.email is an object that is being updated every time thru the loop. So you need to use
var mail = grp_mail.email.toString();