Skip to main content
Solved

Adding API value into Linked Record field

  • August 18, 2023
  • 1 reply
  • 143 views

auekk2787
Forum|alt.badge.img+12

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

 

 

 

Best answer by auekk2787

I figured it out - changed to 

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

 

1 reply

auekk2787
Forum|alt.badge.img+12
  • Author
  • Brainy
  • 36 replies
  • Answer
  • August 18, 2023

I figured it out - changed to 

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