Create unique array of sys ids
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2023 09:05 PM
Hi everyone,
I have an array of multiple sys ids in that some sys ids are same.
I need to create an unique array my code is working properly in the Background script but not working in script include please help me with this.
If you have any other method that also will be acceptable.
Code:
var abc2 = ['ac5e60f41b835c14e9b220202d4bcb26','43544150dbf41700154ce3334a961904','9afbbac71b3fe054e9b220202d4bcbd7','3aa0f8a3db860454e8aae5644a9619ac','9afbbac71b3fe054e9b220202d4bcbd7','ac5e60f41b835c14e9b220202d4bcb26','9afbbac71b3fe054e9b220202d4bcbd7'];
var arr2 = [1];
var v1;
var ntc;
for (var i = 0; i < abc2.length; i++) {
ntc = abc2[i].toString();
gs.info('value of ntc is:' + ntc);
v1 = arr2.indexOf(ntc);
gs.info('Value of v1 is: ' + v1);
if (v1 == '-1') {
//gs.info(''));
arr2.push(ntc).toString();
gs.info('Was not present in list');
} else {
gs.info('Already present');
}
}
//arr2.toString().shift();
gs.info('array of resp : ' + arr2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2023 08:10 PM
Hi @shekhar_jain ,
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
If not reply and share details.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar