Help

Script exceeded execution time limit of 30 seconds

Topic Labels: Automations
178 2
cancel
Showing results for 
Search instead for 
Did you mean: 
jakepap
5 - Automation Enthusiast
5 - Automation Enthusiast
Hey, I'm getting a time limit error for the below script only for some records. 
 
let table = base.getTable("Photos"); // Change "YourTableName" to your actual table name
let query = await table.selectRecordsAsync();

// Object to hold the count of each Claim-Fault combination
let counts = {};

// First pass to count occurrences
for (let record of query.records) {
    let claimNumber = record.getCellValue("Claim Number");
    let faultNumber = record.getCellValue("Fault No.");
    let identifier = `${claimNumber}-${faultNumber}`;

    if (counts[identifier]) {
        counts[identifier].push(record.id);
    } else {
        counts[identifier] = [record.id];
    }
}

// Second pass to update the Index field
for (let identifier in counts) {
    let recordIds = counts[identifier];
    for (let index in recordIds) {
        await table.updateRecordAsync(recordIds[index], {
            "Index": "." + index
        });
    }
}

console.log("Indexing complete.");
 
Is there anyway to extend the time limit?
2 Replies 2

Nope, there isn't a way to extend the limit I'm afraid.  Try optimizing your code by using `updateRecordsAsync` instead of `updateRecordAsync`, should solve the problem

https://airtable.com/developers/scripting/api/table#update-records-async

Hi,
Time limit exists in automations. Did you try to run it in script extensions?
I wonder what's the purpose of the script and what's the fields type.