Trouble appending linked record

Topic Labels: Scripting extentions
1012 3
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

I have looked at other postings regarding this same topic and cannot determine why I keep throwing a specific error.

We are attempting to utilize a project management setup where there is a list of issues. An issue can be a parent or can be linked to a parent record (in a linked record field called “Parent”). For sorting and interface purposes, I am working to set up an automation that will add the children to the parent record (in a linked field called “Child”).

I’ve written a script that will allow the child records to be appended, but I keep getting an error that the Child field “cannot accept the provided value” when I try to spread the existing array. What am I missing here?

Airtable Script

3 Replies 3

The value of linked records fields is an array of objects with two key/value pairs: the id and the name. You only need the id.

...(parentRecord.getCellValue('Child') || []).map(x => return {id:})

^ try using the line above where you’re currently trying to spread the value of that field. My example attempts to account for null values by replacing null/undefined lists of linked records with an empty array.

Looking at the example code, it doesn’t seem to indicate a need to pull out the id from the object array so I am confused about that.

I did attempt to use the line you provided and got an error about “return.” I’m not completely familiar with the map function, but after looking into it, I removed “return” since it doesn’t seem to be needed in a one-line map function. Doing so removed that error, but still causes an error similar to the first one I shared. It seems that mapping created an array of the correct length, but a console log indicates that each element is undefined.

Airtable Script 2

4 - Data Explorer
4 - Data Explorer

Okay, I did some more research on mapping and was able to convert to an array of just the ids, but my original issue still stands. There is something else going on here that is preventing the linked record field from accepting the spread array before the new record.

EDIT: I forgot to clear the contents of the field before trying with the newly mapped array. After doing that, the new mapping appeared to have solved the issue. However, there is still an error if the array contains the new record. I’ll have to filter it out.

EDIT 2: I could have sworn I had tried with an empty field the first time, but the old method works without having to remap the record array. I’ve added a check to make sure the record doesn’t already exist in the array and looks like everything is working just fine.