Background script stops after 5 mins

sathis sky
Tera Contributor

Hi,

 

When script runs for counting Discovered item that does not have vulnerable item. It takes so much times to completed. After 5 mins of running, Scripts screen error as "Service interrupt, this instance is unavailable". Unable to get any results. some things, Script continue to runs in backgrounds and needs to kill it in active transitions. But we don't get count or rollback option.

Please provide suggestion to clear this error.


Script which try to run:

var diCount = 0;
var dicount2 = 0;
var di = new GlideRecord('sn_sec_cmn_src_ci');
di.addEncodedQuery('state=unmatched');
di.query();

gs.log('total count of the DI in this filter: ' + di.getRowCount());

while (di.next()) {

//Checking Di has VITs
var vit = new GlideAggregate('sn_vul_vulnerable_item');
vit.addQuery('src_ci', di.sys_id);
vit.addAggregate('COUNT');
vit.query();
var count = 0;
if (vit.next())
count = vit.getAggregate('COUNT');

if (count == 0) {
diCount++;
} else
dicount2++;
}
gs.log('total di count without VIT : ' + diCount);
gs.log('total di count with VIT : ' + dicount2);

6 REPLIES 6

Thanks Chris for suggestion.
For above example script, I have get the list of Discovered item (sn_sec_cmn_src_ci) without vulnerable item (sn_vul_vulnerable_item) in output. Fix scripts don't have clear output, it shows all execution history. 
Can we able to re-direct the output to file separately? 

I share your pain on this..... 🤣

Typically, I write the records to an import set table (Load data... then create a new table... then dump data there.... kind of like a temp table... because the data get purged every ~7 days)

or

https://www.servicenow.com/community/developer-articles/generate-csv-file-through-script/ta-p/231977...

And attach it to some Incident