Airtable ascript code was written in airtable to retrieve record information from table A with the email address as the key, add up the points associated with the same email address, and then store the combined value in the aggregate column of the record associated with the email address in table B.
The Airtable Script test passes without any problems, but when I actually update Table A, no values are reflected.
Additionally, no errors are generated and no error log is displayed.
Could someone please lend me some wisdom?
==========================================================================
async function calculateTotalPoints() {try {
// Get all records from Table A
const tableARecords = await base('contribution Calc').get();
// Initialize an empty object to store user points
const userPoints = {};
// Iterate through each record in Table A
for (const recordA of tableARecords) {
// Get the user's email address from Table A record
const userEmail = recordA.getCellValue('Email');
// Get the point value from Table A record
const pointValue = recordA.getCellValue('Point');
// If the user exists in the userPoints object, add the new point value to the existing points
if (userPoints[userEmail]) {
userPoints[userEmail] += pointValue;
} else {
// If the user is new, add their email address and point value to the userPoints object
userPoints[userEmail] = pointValue;
}
}
// Update the "Total Points" field for each user in Table B
for (const [userEmail, totalPoints] of Object.entries(userPoints)) {
// Find the corresponding user record in Table B
const userBRecord = await base('Users').find(userEmail);
// If the user record exists in Table B, update the "Total Points" field
if (userBRecord) {
await userBRecord.update({ 'Total Points': totalPoints });
}
}
} catch (error) {
console.error("Error occurred:", error);
}
}