Update and keep values in UpdateRecordsAsync

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.

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:

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