Re: Scripting - Updating an linked record, Error: Field "fldxxx" cannot accept the provided value

1714 0
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

Hello again, community!

I have a script that is throwing an error and would like some help from the community.

I’m using two “for… of” loops. The first finds IDs of records in another table that match a condition. The IDs get pushed into the “familiesToAdd” array which works great. As you can see in the screenshot, the second loop throws an error. In the past I have used the same structure to update multiple linked record fields using the spread operator and it has worked just fine. The values that are being provided are certainly strings. Can anyone see anything that looks off? I would be happy to send in more screenshots.


Screen Shot 2022-04-26 at 12.01.55 PM

7 Replies 7

It’s hard to troubleshoot without seeing your field types and data. But your second loop does not look right. You keep updating the same record in each iteration of the loop. Line 19 also doesn’t feel right to me.

I’m certainly not asking anyone to troubleshoot my code who does not have time, and I agree that it looks off. I’m using spread syntax like in the API example, and essentially doing it one time for each item in the array. Without spread syntax, the array would overwrite the current cell value which I do not want. If given an array of record IDs, do you have a general strategy for adding all of the to a multiple linked record field?

4 - Data Explorer
4 - Data Explorer

Screen Shot 2022-04-26 at 1.16.23 PM
To provide better context, if I remove the spread operator, as in this screenshot, the script does not throw an error but overwrites the field value each time through the loop, resulting in a field value with of only the last ID that I would like to add. Before the script is ran, there are a few dozen linked records. I would like to add in a a few dozen more that match a condition from the first loop. Reaching out to see if anyone else has written a script that accomplishes this and would like to share their process :slightly_smiling_face:

Sorry if I came off a bit prickly today. I was partially frustrated because the code looked off, but I couldn’t pinpoint why.

Coming back to this, I would expect something more like this without the second for loop.

const existingValues = assignmentRecord.getCellVaue('Families Enrolled')
const newValues = => {id: familyId})
console.log({existingValues, newValues})

await assignmentsTable.updateRecordAsync(assignmentRecord, {
  'Families Enrolled': [...existingValues, ...newValues]

Not worries. That approach makes sense. Certainly a bit more concise. I’ll give it a go. Thank you.

4 - Data Explorer
4 - Data Explorer

The above solution suggestion did not get it working. It threw the same error. I was able to get it working properly by emptying the field value and then putting the new linked records in. The use of spread syntax threw an “foo is not iterable” error. Just playing around I got the same error using spread syntax exactly how it is used in the API docs. I’m now curious if anyone has successfully used that to update a record, although that might be a discussion for another topic!

If you run my suggestion, what does the console.log line output when you fully expand the objects?

Do both existingValues and newValues have the same format?

Could you have duplicate values existingValues and newValues? If there is a duplicate record id, Airtable will not let you write that value.

Ther emight be other errors that your try/catch is hiding.