The Airtable Community will undergo scheduled maintenance on September 17 from 10:00 PM PST to 11:15 PM PST. During this period, you may experience temporary disruptions. We apologize for any inconvenience and appreciate your understanding.
Each time an Enrollment form creates a new record in the Classes table, the script creates a record for each Student in the Grades table. Grades table is a junction table linking Classes and Students tables.
I know there are several community scripts regarding junction tables but I need one that works from just one Class record at a time.
//Generate Grade record for each Student registered in user-selected Class
let classesT = base.getTable('Class');
let eachClass = await input.recordAsync ('Select the Class', classesT);
let gradesT = base.getTable('Grades');
// for each student in the students array
for (let student of eachClass.getCellValue('Students')) {
// create a grade record
await gradesT.createRecordAsync({
'Class': [{id: eachClass.id}],
'Student': [{id: student.id}]
})
}
//Generate Grade record for each Student registered in user-selected Class
let classesT = base.getTable('Class');
let eachClass = await input.recordAsync ('Select the Class', classesT);
let gradesT = base.getTable('Grades');
// for each student in the students array
for (let student of eachClass.getCellValue('Students')) {
// create a grade record
await gradesT.createRecordAsync({
'Class': [{id: eachClass.id}],
'Student': [{id: student.id}]
})
}