Re: Update and keep values in UpdateRecordsAsync

3201 2
Showing results for 
Search instead for 
Did you mean: 
8 - Airtable Astronomer
8 - Airtable Astronomer

Hi there -

I have it working to update individual records in updateRecordAsync but it’s replacing the cell values. How can I keep from updating the cell values but just update by adding?

This is for a Look-Up field so it requires a different format than string.

3 Replies 3

So, like sustain the current values and simply add additional lookup references? I think that’s what you are driving at.

It requires that you read the existing value (which I believe would be an array of record IDs), push() another value onto that array, and then write the updated array back to the lookup field.

Yeah. I am just not sure the most efficient way to do this. It is working for now as I am doing a .includes to look up if the values are previously there and if not, then it’s adding new ones.

Adding it as an array of {id: id} was the fix, otherwise.

@Rose_Haft1 - this is a link field, yes? If so, the best way is to use the spread operator. From the docs:

When updating an existing linked record cell value, the specified array will overwrite the current cell value. If you want to add a new linked record without deleting the current linked records, you can spread the current cell value like so:

let newForeignRecordIdToLink = 'recXXXXXXXXXXXXXX';
myTable.updateRecordAsync(myRecord, {
    'myLinkedRecordField': [
        { id: newForeignRecordIdToLink }

From MDN:

Screenshot 2021-01-15 at 18.33.09

I’ve got an example of this here (albeit on an attachment field, not a link field, but it is the same idea)