Fix script gets cancelled due to maximum execution time exceeded

Nowlearner
Kilo Guru

Hi,

I have this fix script to fix unassigned tickets with an assignment group. I have like around 150k records to update, but my  script gets timed out.

I tested with 1k records which worked but dealing with huge number my script isn't efficient enough, any thoughts?

runit();

function runit() {
var vg = new GlideRecord('sn_vul_vulnerability');
vg.addEncodedQuery('assignment_group.nameISEMPTY^vulnerability_group_rule=2d8025e41b887c102cc9975f034bcb67^ORvulnerability_group_rule=2ad2fb201bdf6410151c975f034bcb07^ORvulnerability_group_rule=ce9ca1f8db3bdc1090d359e5ca961959^ORvulnerability_group_rule=b0548ab0db3ee4508785dc62ca961942^ORvulnerability_group_rule=5965adc2dbf3985090d359e5ca9619fa^ORvulnerability_group_rule=3ff5f021dbb33fc4399475e6f4961983');
vg.query();
while (vg.next()){
vg.setValue('assignment_group', '6bffdcf8dbe2f41813c6dff648961975');
vg.updateMultiple();
}
}

1 ACCEPTED SOLUTION

Himanshu Gupta1
Mega Guru

Hi

 

yes fix scripts are not capable to proceed with huge records you try scheduled job for the same it will work for you

 Put logs as well in scheduled job so that you will get the information of number of records processed and time taken.

 

Please mark the answer Helpful and correct if applicable

 

Best Regaards

Himanshu Gupta

View solution in original post

14 REPLIES 14

Himanshu Gupta1
Mega Guru

Hi

 

yes fix scripts are not capable to proceed with huge records you try scheduled job for the same it will work for you

 Put logs as well in scheduled job so that you will get the information of number of records processed and time taken.

 

Please mark the answer Helpful and correct if applicable

 

Best Regaards

Himanshu Gupta

Hi @Nowlearner ,

 

is your issue is resolved and if yes then can you please mark the response helpful and correct

Best Regards

Himanshu Gupta

Voona Rohila
Kilo Patron
Kilo Patron

Hi, Modify like below.

use vg.setLimit(1000); before vg.query(); which lets you to limit the number of gliderecord that returns after satisfying the gliderecord condition.

 

runit();

function runit() {
var vg = new GlideRecord('sn_vul_vulnerability');
vg.addEncodedQuery('assignment_group.nameISEMPTY^vulnerability_group_rule=2d8025e41b887c102cc9975f034bcb67^ORvulnerability_group_rule=2ad2fb201bdf6410151c975f034bcb07^ORvulnerability_group_rule=ce9ca1f8db3bdc1090d359e5ca961959^ORvulnerability_group_rule=b0548ab0db3ee4508785dc62ca961942^ORvulnerability_group_rule=5965adc2dbf3985090d359e5ca9619fa^ORvulnerability_group_rule=3ff5f021dbb33fc4399475e6f4961983');
vg.query();
vg.setValue('assignment_group', '6bffdcf8dbe2f41813c6dff648961975');
vg.updateMultiple();
}

or

runit();

function runit() {
var vg = new GlideRecord('sn_vul_vulnerability');
vg.addEncodedQuery('assignment_group.nameISEMPTY^vulnerability_group_rule=2d8025e41b887c102cc9975f034bcb67^ORvulnerability_group_rule=2ad2fb201bdf6410151c975f034bcb07^ORvulnerability_group_rule=ce9ca1f8db3bdc1090d359e5ca961959^ORvulnerability_group_rule=b0548ab0db3ee4508785dc62ca961942^ORvulnerability_group_rule=5965adc2dbf3985090d359e5ca9619fa^ORvulnerability_group_rule=3ff5f021dbb33fc4399475e6f4961983');
vg.query();
while (vg.next()){
vg.setValue('assignment_group', '6bffdcf8dbe2f41813c6dff648961975');
vg.update();
}
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

BhupeshG
Tera Guru

run in background script with no cancel checkbox unchecked.