Not getting the source record of the finding in script-only check.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2022 12:56 AM
I have been trying to define a Script-Only check in the Instance Scan module of ServiceNow, which should show up all the update sets having duplicate names.
Below is the Script that I have written:
(function(engine) {
// Add your code here
var update_set = new GlideAggregate('sys_update_set');
update_set.addAggregate('COUNT');
update_set.query();
while (update_set.next()){
var no_of_records = update_set.getAggregate('COUNT');
var update_set_records = [];
update_set_records.push(update_set.getValue('name'));
}
var i = 0;
while (i < no_of_records) {
if (update_set_records[i] == update_set_records[i + 1]) {
engine.finding.setCurrentSource(update_set);
engine.finding.increment();
}
i++;
}
})(engine);
Here, after setting up the setCurrentSource('update_set'), I am getting the source table, but still not getting that exact record which satisfies the condition.
Please let me know if there is any other method under the engine or the finding object which specifies the record as well, or is there any other way to do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 02:50 AM
That is expected.
If you have 11 records each has one duplicate then it will show both the records. (22 records)
System cannot differentiate which one is needed for you and which one is not needed for you if both are in same name.
What if you have 3 or more records with same name. which one do you want to identify and which one you will ignore. You cant do that so it will show both the records in findings.
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2022 08:34 PM
Hi Sumanth,
Is there a scope to use the ArrayUtil() API to fetch the unique values in this code somewhere? We have something called as the unique() method of the ArrayUtil. So is there any scope to use that and extract just the unique values?
Any help would be appreciated regarding the same.
Regards,
Sudhangshu Das