Fix script error - 'maximum execution time exceeded'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 10:35 AM - edited 03-25-2024 05:54 AM
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.
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.
What could be the issue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 12:24 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 12:54 PM
@Suggy , did you try clicking proceed in background in fix script ?
i have a simple code to update ritm please do refer to it to update field
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 05:56 AM
@swathisarang98 Yes, I tried using both the options. Same issue.
I just want to know where is that time restriction coming from
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 06:10 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 06:04 AM
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.