Help

Can't write a RecordID to a linked Field

Topic Labels: Scripting
1999 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Matt_Lister
5 - Automation Enthusiast
5 - Automation Enthusiast
Hi All
 
After many hours of trying, I have to ask for help 😁:
 
I'm getting an error "Field "fldxxxxxxxxx" cannot accept the provided value." The field that is failing is Worker.
 
After testing, everything here works fine and writes well to the base except "Worker": item.workerID.
Worker is a linked field, and I thought it would accept a record ID.
workerID is definately a valid recordID as I've tested in manually by pasting the values into the worker field.
Does anyone know what might be going wrong?
 
const outputTable = base.getTable('Work Weeks');
for (item of result) {
await outputTable.createRecordAsync({ 
"Week Number": item.week,
"Total Hours": item.value,
"Worker": item.workerID,
})};
3 Replies 3
Stephen_Orr1
10 - Mercury
10 - Mercury

Try putting item.workerID in an array of objects like

"Worker": [{id: item.workerID}]

More info: https://airtable.com/developers/scripting/api/cell_values#multiple-record-links

autumn
6 - Interface Innovator
6 - Interface Innovator

I think when updating a linked record field via a script, you have to specify a list of the records you'd like to link to, with each one's record id specified. 

Try reformatting your code like this: 

 

const outputTable = base.getTable('Work Weeks');
for (item of result) {
  await outputTable.createRecordAsync({ 
    "Week Number": item.week,
    "Total Hours": item.value,
    "Worker": [{id: item.workerID}]
  })
};

 

Hi @autumn,

Your suggestion is exactly what I had already recommended.

@Matt_Lister, if my suggestion helps at all here please feel free to mark it as the solution. 

I appreciate it!

-Stephen