Cannot add multiple record IDs to a linked field

Hello all. I’m new to scripting in Airtable. I’ve learned a lot from this forum but cannot resolve a multi-record linking problem.

I have a table of People with a field called Crafts which links to a related table “List - Crafts” which includes records for Director, Writer, Producer, and so on.

In a People record, I want to populate the Crafts field with multiple values. For example, in the Person record “John Doe” the Crafts field would include Director and Writer.

My code queries the “List - Crafts” table and stores the relevant record IDs into an array named idYouNeedArray.

It’s my understanding you need to pass an array of strings to populate the field with multiple values however this code does nothing with the Crafts field.

peopleTbl.updateRecordAsync(foundPeopleRec, {
    "Crafts": [ {id: idYouNeedArray} ]
    });

The only way I can get multiple values into the Crafts field is with this:

peopleTbl.updateRecordAsync(foundPeopleRec, {
    "Crafts": [ {id: idYouNeedArray[0]}, {id: idYouNeedArray[1]} ]
});

However I don’t know how many values my idYouNeedArray array is going to have. It could have none, one, two, or more values.

I followed the example for MULTIPLE_RECORD_LINKS and nothing happens - the Crafts field stays empty.

Any ideas how to get this working? Thank you for your help!

[ {id: idYouNeedArray} ] returns something like this:

[
    {id: ["xxx1", "xxx2", "xxx3"]}
]

When instead you need this:

 [
    {id: "xxx1"},
    {id: "xxx2"},
    {id: "xxx3"},
]

So instead of passing an array of id’s, pass an array of mapped id’s:

let mapped = idYouNeedArray.map(x => (
    {id: x}
))

peopleTbl.updateRecordAsync(foundPeopleRec, {
    "Crafts": mapped
});
2 Likes

Brilliant! That worked. Thank you!!