Aug 18, 2023 02:36 PM
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
})
}
}
Solved! Go to Solution.
Aug 18, 2023 02:49 PM
Aug 18, 2023 02:49 PM
I figured it out - changed to
'School Link' : [{id: school.id}],