Help

Adding API value into Linked Record field

Topic Labels: Extensions
Solved
Jump to Solution
822 1
cancel
Showing results for 
Search instead for 
Did you mean: 
auekk2787
7 - App Architect
7 - App Architect

I have a script, creating records from an API. The API data works fine. Instead, I'm having trouble entering a Linked Field value. I understand it needs to an array, but I can't get it to work.

I have one table of Schools. The script loops through the schools, does an API call using the school ID, then creates records in the Courses table.

"school.id" returns the Airtable record ID correctly in the console log. I need that to be entered in the School Link field at the end. Please let me know what I'm missing.

 

 

let schoolsTable = base.getTable('Schools');
let schoolsView = schoolsTable.getView("Schools View");
let schoolsList = await schoolsView.selectRecordsAsync({fields: ['Account ID']})

//get school IDs
for (let school of schoolsList.records) {
    console.log(school.id)

    let currentCourses = await remoteFetchAsync("https://XXXX", requestOptions);
    const currentCoursesData = await currentCourses.json();
    console.log(currentCoursesData);

//create records for courses returned
let coursesT = base.getTable('Courses');

for (let course of currentCoursesData) {
    output.text(`Creating course ID ${course.id}`)
    await coursesT.createRecordAsync({
        'Course ID': course.id,
        'School Link' : [school.id],
        'Course Name': course.name
    })
}
}

 

 

 

1 Solution

Accepted Solutions
auekk2787
7 - App Architect
7 - App Architect

I figured it out - changed to 

'School Link' : [{id: school.id}],

 

See Solution in Thread

1 Reply 1
auekk2787
7 - App Architect
7 - App Architect

I figured it out - changed to 

'School Link' : [{id: school.id}],