Help

No Airtable script errors, but nothing is updated.

Topic Labels: Automations
206 4
cancel
Showing results for 
Search instead for 
Did you mean: 
DevP
4 - Data Explorer
4 - Data Explorer

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
// @TS-ignore
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);
}
}
4 Replies 4
Dan_Montoya
Community Manager
Community Manager

You don't need a script to do this.  The rollup feature already does this for you.  See this sample Screenshot 2024-04-29 at 9.14.06 AM.png

I'd recommend reading the documentation: https://airtable.com/developers/scripting/api

A lot of the code you're shared doesn't match existing functionality or syntax, e.g. "update" instead of "updateRecordAsync"

Thank you for your reply.

I had already tried Rollup.
If you use Rollup, I think you need to manually enter the values of the fields to explicitly put the relationship with the other tables.
I was considering using the Airtable script because I wanted to avoid manual input.

If it is possible to use Rollup automatically, it would be helpful to know how to do this.

Thank you for your reply.

As a premise, I am neither a programmer nor an engineer.
Therefore, I use AI tools when writing such code.

Well, I will refer to the documentation on that.