I use the script below to retrieve the latest date from all records in table 'personal expenses', and want to insert this value to all records in table 'personal budget' (this table is in the same base).
The script works if I update the records in the same table 'personal expenses', but not when updating the other table 'personal budget'. In that case I receive this error:
j: Error: Failed hyperAssert: undefined
at main on line 33
Can someone help me with debugging? I'm in script noob and assume there's a missing link between selecting the records in tablePersonalExpenses and updating the records in tablePersonalBudget. Thanks in advance!
// Replace "Table Name" with the name of your table
let tablePersonalExpenses = base.getTable("personal expenses");
let tablePersonalBudget = base.getTable("personal budget");
console.log(tablePersonalExpenses)
console.log(tablePersonalBudget)
// Replace "Date" with the name of the date field you want to find the latest date of
let query = await tablePersonalExpenses.selectRecordsAsync({
fields: ["Date"],
sorts: [{field: "Date", direction: "desc"}],
maxRecords: 1
});
// Get the latest date value
let latestDate = query.records[0].getCellValue("Date");
console.log(latestDate)
// Update the value of field "" in all records with the highest value
let updateRecords = query.records.map(function(record) {
return {
id: record.id,
fields: {
"Latest Import Date": latestDate
}
};
});
// Update records - Only up to 50 updates are allowed at one time, so do it in batches
while (updateRecords.length > 0) {
await tablePersonalBudget.updateRecordsAsync(updateRecords.slice(0, 50));
updateRecords = updateRecords.slice(50);
}