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

Hi

As per servicenow functionality if you have to populate  reference field then you have provide/send its sys id only there is not other way.

 

Please mark the answer Helpful and Correct If applicable

 

Best Regards

Himanshu Gupta

assignment_group is a refernce field so mapping with sys_id of group is recomended.

if you already have names and want to map then use this code to get sys_id of group.

var group= '';//give default sys_id if group is not found.
var gr=new GlideRecord('sys_user_group');
if(gr.get('name','group_name'))
group = gr.sys_id; //mapping sys_id based on group name.

 


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

This worked, thank you!

You should be able to do vg.setDisplayValue('assignment_group','abc');

I don't think that 2 hours to update 150k records is poor performance if I am honest thats over 1200 records per minute. As this is a fix script you aren't going to run it often so I would just run it in a maintenance window.

Nestor Paredes
Tera Contributor

May not be what you are looking for, but using ""

 

find_real_file.png

 

Usually allows me to un the script for a longer time (I've seen up to 57 minutes, completed).

 

You can then check the background workers on the (sys_progress_worker) table.