Help

Welcome to the Airtable Community! If you're new here, check out our Getting Started area to get the most out of your community experience.

Junction records automation

Topic Labels: Scripting extentions
Solved
Jump to Solution
252 1
cancel
Showing results for 
Search instead for 
Did you mean: 

I need help writing the following script:

Tables:

  • Classes
  • Students
  • Grades (junction table)

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.

1 Solution

Accepted Solutions

I finally figured it out:

//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}]
    })
}

See Solution in Thread

1 Reply 1

I finally figured it out:

//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}]
    })
}