May 01, 2022 08:21 AM
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!
May 05, 2022 03:04 AM
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} }
May 16, 2022 04:29 AM
Thanks @kuovonne and everyone. It is working:
May 16, 2022 06:11 AM
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.
May 16, 2022 10:47 AM
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}))
})