Fix script error - 'maximum execution time exceeded'

Suggy
Giga Sage

Hello, I am running a fix script which will update the few fields on a table.

After 180s, I got this message. I see that around 1500 records got updated and the script had to update around 2k more records but then got this message.

 

Suggy_0-1711301639720.png

Below is the script:

var rec = new GlideRecord('u_tableau'); 

rec.addEncodedQuery("sys_domain=f5b0bd2800e34444d9a15f45c6cfg466");

rec.query(); 

 while(rec.next()) {           

   rec.setWorkflow(false);

   rec.setValue('short_description','Deactivating as per G12 policy');

  rec.setValue('u_str1','Approved');

   rec.setValue('u_str2', 'Deactivated')

  rec.setValue('active','false');

   rec.update();

 

I checked in Transactio quota rules, its set to 4 hours.

Suggy_2-1711301692629.png

 

What could be the issue?

 

9 REPLIES 9

Hi, instead of querying sys_domain I think the best practice approach would be to query sys_domain_path. Otherwise, your script syntax appears to be ok (at least to my eye) and no reference\parent field updates, so nothing obviously recursive.
Is the target scoped? if yes does the script run ok if run as a background fix script?
If not scoped, does the script behave the same if run in a background window?

 

If the script is timing out consistently at 180 seconds +/- and no obvious cause I would be inclined to log to NowSupport for clarification of the issue.

 

@Suggy , did you try clicking proceed in background  in fix script ?

swathisarang98_0-1711309943177.png

i have a simple code to update ritm please do refer to it to update field 

swathisarang98_1-1711310030982.png

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

 

 

@swathisarang98 Yes, I tried using both the options. Same issue.

I just want to know where is that time restriction coming from

@Suggy  as you have mentioned there are 2k data so fix script can nit process large number of data so try doing it in chunks like add limit

 

rec.setLimit(500); before rec.query();

and update enocded query as below,

rec.addEncodedQuery("active=true^sys_domain=f5b0bd2800e34444d9a15f45c6cfg466");

 

You have to run your script multiple times until all your records are updated

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Georgi Yordano1
ServiceNow Employee
ServiceNow Employee

My only advice would be to avoid using the same iterator.. I think that you might be running in some overflow or some other type of memory issue. For the exercise you are doing, I would use GlideRecord.updateMultiple() as you aren't having any conditions. This should reduce the run time of the script dramatically! 

Right now each time you do rec.next it needs to fetch the values from the DB Query, then add them as references to your GR object, and this takes processing time. The GlideRecord.updateMultiple has been created for exactly such cases where you need a lot of updates.