Help

Re: Automation script exceeds 30 sec limit

Solved
Jump to Solution
1703 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Alexi_Mosnov
6 - Interface Innovator
6 - Interface Innovator

My script was working and then it wasn't after I increased my records from 50 to 100. With 100 records the script was being terminated after 30 seconds. 30 real time seconds is an eternity for computers. I will paste my simple script below and appreciate if you can provide some insight on why the script runs so slowly.

First some background. My first Airtable automation triggers on a change to a Field in a Table. The following action is Find Records there are conditions in the action and the found records are output as a list of records that past the conditions. Next was the Repetable action that can take the list of records as input and inside I added the Update Record action. Here I hit the wall, for the life of  me I could find no way to auto extract the Record ID from the individual records in the list as input to Update Record.

Next I turned to Make but ended in the weeds with the same issue. I used the same Airtable actions except Repetable was replaced with a Make Iterator. But ended in the same place as before. Could not auto extract the Record IDs  from the records in the list in the Update Record action.

Next up Zapier and ChatGPT actually helped me write a working Zap this time. One big problem I'm not going to pay $50/mth to create less than a handful of Zaps.

I decided to look at creating a new Airtable automation using a script with the help of ChatGPT. I know nothing about writing in JavaScript. So now I have a trigger followed by a script action. The first script did not work it used findbyformula function with my conditions inside it. It did not work it ignored my conditions and spat out all 50 records on each run. Finally  I asked ChatGPT to replace the findbyformula function with a for loop. ChatGPT warned me that a for loop was less efficient but this time the script worked until I doubled the number of records and my runs were being terminated after 30 seconds.

My end target is a 1000 records to process in the table.

Here is the script code:

// Update Records script
// This script was created to update fields of records in a base based on fields meeting certain conditions.

// The Airtable built-in Update Record action does not support extracting a Record ID from a record in list of records provided from the Find Records action. This script performs updating records without manually providing a Record ID.


// Define the table you're working with
let table = base.getTable("300 Replens 2");

// Fetch all records from the table
let queryResult = await table.selectRecordsAsync();

// Get the records from the query result
let records = queryResult.records;

// Loop through each record in the records array
for (let record of records) {
// Get the values of the "Net Profit", "ROI", etc. fields for the current record
let netProfit = record.getCellValue("Net Profit");
let roi = record.getCellValue("ROI");
let avgrank90 = record.getCellValue("Average Rank (90 Days)");
let amz3x = record.getCellValue("Amazon 3x Cost");
let packqty = record.getCellValue("Pack QTY");
let estmth = record.getCellValue("Estimated Monthly Sales");
let fba5 = record.getCellValue("# of FBA Sellers");
let eum = record.getCellValue("EUM");
let epm = record.getCellValue("EPM");
let rating = record.getCellValue("Rating");
let reviews = record.getCellValue("Reviews");
let prodsz = record.getCellValue("Product Size");
let amazon = record.getCellValue("Amazon Sells and in Stock");

// Check the conditions for the current record
if (
netProfit < 2 ||
roi < 0.4 ||
avgrank90 > 99999 ||
amz3x < 3.0 ||
packqty > 2 ||
estmth < 10 ||
fba5 > 5 ||
eum < 10 ||
epm < 13.00 ||
rating < 3.0 ||
reviews < 10 ||
prodsz.includes("Oversize") ||
amazon.includes("yes")
)
{
// If either condition is met, define the new field values you want to set
let updateFields = {
'Buy/Do not Buy': 'Do not Buy'
// ...add more fields as needed
};

// Update the current record with the new field values
await table.updateRecordAsync(record.id, updateFields);
}
}

// Log a message to indicate the script has finished running
console.log('Updated all records.');

Thank you for your assistance. In a post @ScottWorld recommended using Make for this stating in reference to Airtable actions that conditions don't play with repetion in Airtable. So I'm currently taking a fresh look at Make (much cheaper than Zapier)

 

1 Solution

Accepted Solutions
Alexi_Mosnov
6 - Interface Innovator
6 - Interface Innovator

Thanks @ScottWorld I actuall have my Make scenario working. Cheers!

See Solution in Thread

4 Replies 4
Sho
11 - Venus
11 - Venus

Updating with updateRecordAsync() for each record is very slow.

How about using updateRecordsAsync(), which generates an array of records in the first For statement and can update 50 records at a time for updates?

Hi @Alexi_Mosnov,

Thanks for the shoutout! 😀

Yes, I highly recommend Make over Zapier, because Make is SIGNIFICANTLY cheaper and INFINITELY more powerful than Zapier.

I give a few more reasons why Make is the superior platform in this post: Make vs. Zapier.

There is a small learning curve with Make, which is why I created this basic navigation video to help. I also provide the links to a few other Make training resources there as well. 

Alexi_Mosnov
6 - Interface Innovator
6 - Interface Innovator

Thanks @ScottWorld I actuall have my Make scenario working. Cheers!

I am not using a script I managed to get my automatiom working with airtable actions with help from here figured out the correct configuration for Update Record when receiving records from a repeatable action.