I've created a base for my softball league and could use a second set of eyes on a problem I can't seem to crack. I want to be able to input the game scores in the "Schedule" tab and then have everything else update accordingly (runs scored, runs allowed, standings, etc.). I'm not sure how to accomplish this.
LINK TO THE BASE: https://airtable.com/appyRHUtLhxlpEWFY/shrn9oSvblGrwjaEY
I also have this script I could run, but would need to upgrade my plan and I'd rather not have to do that:
let gamesTable = base.getTable("Games");
let standingsTable = base.getTable("Standings");
let gamesQuery = await gamesTable.selectRecordsAsync();
let standingsQuery = await standingsTable.selectRecordsAsync();
let standings = {};
standingsQuery.records.forEach(record => {
standings[record.getCellValue("Team")] = record;
});
gamesQuery.records.forEach(record => {
let homeTeam = record.getCellValue("Home Team");
let awayTeam = record.getCellValue("Away Team");
let homeScore = record.getCellValue("Home Team Score");
let awayScore = record.getCellValue("Away Team Score");
updateStanding(homeTeam, homeScore);
updateStanding(awayTeam, awayScore);
});
async function updateStanding(team, score) {
let standingRecord = standings[team];
let currentScore = standingRecord ? standingRecord.getCellValue("Total Score") : 0;
let newScore = currentScore + score;
if (standingRecord) {
await standingsTable.updateRecordAsync(standingRecord, {
"Total Score": newScore
});
} else {
await standingsTable.createRecordAsync({
"Team": team,
"Total Score": newScore
});
}
}