ArrayUtil not working

revathy
Kilo Expert

Hi,

 

script :
for(var i=0 ; i<count.length ; i++){
var con = new GlideRecord('core_country');
con.addQuery('sys_id',count[i]);
con.query();
if (con.next()) {
reg.push(con.u_region);
}
}
//gs.log('newchange reg: '+reg);
var arrayUtil = new ArrayUtil();
var arr= arrayUtil.unique(reg);
//gs.log('newchange arr: '+arr);
//gs.log('newchange : '+arr.length);

 

Array util is not fetching the unique values.

log result:

newchange arr: b23c19224faa36049bf687dab110c7b7,b23c19224faa36049bf687dab110c7b7

newchange : 2

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Revathy,

Can you update your code as below and check it once. changes are highlighted in bold

script :
for(var i=0 ; i<count.length ; i++){
var con = new GlideRecord('core_country');
con.addQuery('sys_id',count[i]);
con.query();
if (con.next()) {
reg.push(con.u_region.toString());
}
}
//gs.log('newchange reg: '+reg);
var arrayUtil = new ArrayUtil();
var arr= arrayUtil.unique(reg);
//gs.log('newchange arr: '+arr);
//gs.log('newchange : '+arr.length);

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Revathy,

Can you update your code as below and check it once. changes are highlighted in bold

script :
for(var i=0 ; i<count.length ; i++){
var con = new GlideRecord('core_country');
con.addQuery('sys_id',count[i]);
con.query();
if (con.next()) {
reg.push(con.u_region.toString());
}
}
//gs.log('newchange reg: '+reg);
var arrayUtil = new ArrayUtil();
var arr= arrayUtil.unique(reg);
//gs.log('newchange arr: '+arr);
//gs.log('newchange : '+arr.length);

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks a lot!!

It worked!!!!!!!!!!!!

kristenankeny
Tera Guru

Make sure that prior to the script excerpt you show above that you  declare var reg = [];

Then, for the arrayutil bit, try:

reg = new ArrayUtil().unique(reg);

manukundur
Giga Contributor

I had the same issue and it got resolved by converting my array elements to .toString().