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

Community Alums
Not applicable

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?

11 REPLIES 11

SumanthDosapati
Mega Sage
Mega Sage

Hi,

I guess the is is due to that setCurrentSource() accepts only a GlideRecord object as a parameter but you are passing a GlideAggregate obj.

Try passing a GlideRecord object and see if you are still facing an issue.

 

Mark as correct and helpful if it solved your query.

Regards,

Sumanth

 

Community Alums
Not applicable

Hi there,

Is there any way to do that using the GlideAggregate object as well, as I need to count the records using GlideAggregate(). Please let me know if you have any idea.

Regards,

Sudhangshu Das

setCurrentSource() supports only glideRecord object.

If you want count of records then you can use GlideRecord and get the count using gr.getRowCount();

 

Mark as correct and helpful if it solved your query.

Regards,

Sumanth

Community Alums
Not applicable

Even if I use GlideRecord, it is throwing up same record in multiple findings. Please let me know if I can change anything in the script logic.

Thanks.