I have written the script below to select records from one table in my base and insert them as new records in a second table. The script is working, however it times out after running for 30 seconds.
The process is selecting and creating about 200 records. Is there a more efficient way of writing this script so that it happens faster and doesn't hit the 30 second limit? I've read that maybe i need to create an array so that multiple records are inserted at once, but I am brand new to scripting and not sure how to achieve this.
Any updates / changes / suggestions would be most welcome!
Thanks
//Script Purpose:
//1. Select fields "Client" and "Client Family" from all records in the table "Client Master"
//2. Using these values, create new records in the table "Bank Recs"
//Define source table
let table = base.getTable("Client Master");
//define fields to retrieve
const fldClient = table.getField("Client")
const fldClientFamily = table.getField("Client Family")
//query for all records in the Client Master Table
//Select specific Fields from that table, sort by Client Family then by Client
const queryResult = await table.selectRecordsAsync({fields: [fldClient,fldClientFamily],
sorts: [
// sort by "Client Family" in ascending order
{field: fldClientFamily},
// then by "Client" in ascending order.
{field: fldClient},
]
});
//View Query Result
console.log({queryResult})
//Define target table for creating new records
let targetTable = base.getTable("Bank Recs");
//Loop through all records in the found records
for (let record of queryResult.records) {
await targetTable.createRecordsAsync([
{
fields: {
"Client": record.getCellValueAsString("Client"),"Client Family": record.getCellValueAsString("Client Family")
},
},
]);
}