Help

List of IDs CreateRecordsASync

Topic Labels: Scripting extentions
2404 13
cancel
Showing results for 
Search instead for 
Did you mean: 
Rose_Haft1
8 - Airtable Astronomer
8 - Airtable Astronomer

Hi there - How is it possible to add a list of IDs into a createrecordasync function?

For instance, we have:

id_array: [recK0FKsUDicD8Lar,recP4uFoqMq9qJquY,recudo4XILtrW5IYd]

const table_Output = base.getTable(“Output_Results”)
table_Output.createRecordsAsync([
{fields: {
Client: [{id: clientID}],
Symptom: [{id: {id_array}]}
}])

where we replace id_array with the actual array

Thanks!

13 Replies 13

I would use mentioned function ‘map’, which loops through array of IDs and returns array of objects like {id: recordID}

const symptom=id_array.map(recordID => ({id: recordID}))
const toCreate={fields: {Client: [{id: clientID}], Symptom: symptom} }

Rose_Haft1
8 - Airtable Astronomer
8 - Airtable Astronomer

Thanks @kuovonne and everyone. It is working:

Glad you got it working. Do you mind sharing what specifically solved your issue? (It can be hard to identify the key concept in an entire base share.) This could help anyone else with a similar issue who later reads this thread.

@kuovonne

Here is the code I used. It worked when I did what you asked. I originally thought you meant to do the mapping in the loop, so it wasn’t working but it worked when I put it in the createrecords command:

var t_links = base.getTable("Table 1")

var t_links_aw = await t_links.selectRecordsAsync

var t_table = base.getTable("Test linking")

var t_table_aw = await t_table.selectRecordsAsync

var arr_id = []

arr_id.push("recmi56Y9WQiRd3B5")

arr_id.push("recOQdZvyp7AKDOFm")

arr_id.push("rec4cHGYeA1S6p9y1")

t_table.createRecordAsync({

    Name: "This is a name",

    linked: arr_id.map(recordID => ({id: recordID}))

    })