- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 06:44 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 06:54 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 06:54 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 07:00 AM
Thanks a lot!!
It worked!!!!!!!!!!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2018 06:55 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2018 12:53 PM
I had the same issue and it got resolved by converting my array elements to .toString().