- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Aug 17, 2023 06:50 PM
Hello,
When I run the script below as an automation, I get an error:
Script exceeded execution time limit of 30 seconds
Here is the code:
Is there a way to edit this script so it shortens the timeframe of running?
Any help is greatly appreciated! 🙂

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Aug 17, 2023 09:50 PM - edited ‎Aug 17, 2023 09:58 PM
The most obvious optimization is to change the table.updateRecordAsync() to table.updateRecordsAsync() (note that it can only process 50 records at a time). Where you currently update the record, instead push the update to an array, and then update the records in a batch outside of the loop. Even though the operations are supposed to be asynchronous and can run concurrently, if you're updating a large number of records, the run time can add up.
You can additionally optimize the code by:
- only requesting the two fields you access with table.selectRecordsAsync({fields: ['DA Amount','Customer & Week']}).
- assigning 'Customer & Week' to the result.records array objects so you don't have to call getCellValue three times in the script
- for the "updated" block of code, you can iterate directly using sum.forEach((value, index) => {...}) (you've already created an array where the index itself is a list of unique customerAndWeek values, so you don't really need the 'updated' variable to keep track of what has been updated)
