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

This is in fact the correct answer.


If this answer was helpful, I would appreciate if you marked it as such - thanks!

Best
Daniel

Richard Hine
Tera Guru
Tera Guru

Hi,

I think I see opportunities for improvements in your code. I would separate the query from the update which should help things run quicker using updateMultiple.

You can then use the array of matching records as a IN clause to a second query and do a mass update.

** This is example code and has not neen tested, the responsibility is on you to test in a non-production environment first and validate that it suits your need **

 

runit();

function runit() {
	var vgArray = [];
	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();

	// Loop the found records and push them into an array.
	while(vg.next()){
		vgArray.push(vg.getUniqueValue());
	}

	// Declare a new GlideRecord for clarity though this shouldn't be necessary.
	var vgUpdate = new GlideRecord('sn_vul_vulnerability');
	vgUpdate.addQuery('sys_id','IN', vgArray.toString());
	vgUpdate.setValue('assignment_group', '6bffdcf8dbe2f41813c6dff648961975');
	vgUpdate.updateMultiple();
}

 

Hope this is of some help....

Richard

i tried this but updateMultiple() isnt as quick as update(). Also i am trying to use the assignmnet group name instead of sys id to update tickets but it doesnt seem to work.

Because we have sys ids different for groups across environments and want to use the name isntead.

vg.setValue('assignment_group', 'abc'); - this doesnt work 

vg.setValue('assignment_group', '2354678jbfsjd1325445) - only sys id works

The scheduled job is also taking 2 hrs time to update 150 k records, any recommendations to reduce the time?

 

Hi

 

See 2 hours time is just fine for that many records you run with your scheduled job and everything will be in place

 

Can you please mark the response Helpful and Correct If applicable

 

Best Regards

Himanshu Gupta

@Himanshu Gupta Thanks for your response. Any idea how to use the group name instead of sys id to update the tickets?