Help

Re: Script exceeded execution time limit for 30 seconds

730 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Harry_McDonald
6 - Interface Innovator
6 - Interface Innovator

Hey there,

I have a script which:

  1. Takes the Qty of a product and creates rows in another table based on this qty.
  2. At the same time it maps 2 x Linked Record fields and sets the row ‘Status-’ to a pre-defined value.

The script is running wonderfully until the ‘Qty’ of a product starts to increase - for example I received the ‘Script exceeded execution time limit for 30 seconds’ error based on a qty of 380.

I’m a little confused at why this is occurring and wondering if anyone has any suggestions on the script posted below?

Thanks in advance.

let inputConfig = input.config()
let originalLineItem = inputConfig.originalLineItem
let originalProject = inputConfig.originalProject
let quantity= inputConfig.quantity



let tableToUpdate = base.getTable('Inventory Ledger')
let updates = new Array

for (let i = 0; i < quantity; i++){
    updates.push({
        "fields": {
            "Stock! Linked": [{id:originalLineItem[0]}],
            "Allocated to (remember late is best)": [{id:originalProject[0]}],
            "Status-": {name: 'Forecast (we need at some point in the future)'},
        }
    })
}

while (updates.length > 0) {
    await tableToUpdate.createRecordsAsync(updates.slice(0, 50));
    updates = updates.slice(50);
}

7 Replies 7

It looks like you are already sending the requests in batches of 50. However, 380 records is a lot of records to create at in one automation. With batches of 50 records, it still takes 8 batches. Each batch can take several seconds to process. If each batch averages 3.75 seconds, those eight batches takes 30 seconds.

You have no control over how long it takes Airtable to create a batch of records. The time depends on how busy Airtable’s servers are, and the complexity of your base schema. Records with complex formula chains of lots of lookups/rollups take longer to create.

On the other hand, you might not need to await the results of the request to create the records. If you do not await the request, you can send up to 15 requests per second. This still has performance implications for the base as a whole, but you would be able to submit your requests to create 380 records within those 30 seconds.

Yet, I still wonder at the need to automatically create multiple hundreds of records all at once. If you do this very often you will quickly reach the record limits of the base.

Thanks for the response, helpful as always.

Would you mind elaborating on ‘not needing to await results’ and how I could look to implement?

This is a test for an inventory management system, where each record represents a product which can be allocated and have its status tracked independently. The automation won’t be running very frequently only when new inventory is added to the system.

Leave out the await keyword. And if you are creating more than 750 records, make sure that you add in a pause so that you do not exceed the 15 mutations per second rate limit.

Thanks again. Removing the await keyword worked but I’m confused about the pause and where I would add this. If anyone else had any ideas that would be awesome.

Do you not understand the reason for needing a pause if you have over 750 records to create?

Or do you not know how to implement a pause?
If so, you can search these forums for how to script a pause.

var millisecondsToWait = 500;
setTimeout(function() {
    // Whatever you want to do after the wait
}, millisecondsToWait);

//Pauses your execution

Welcome to the Airtable community!

Thank you for trying to help out others on this forum. However, setTimeout is not available in an automation script. There are other workarounds on these forums for implementing a pause in an automation script.