Help

Re: List of IDs CreateRecordsASync

3230 0
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

It looks like you are trying to set the field value of a linked record field. To do this you need an array of objects, as specified in the scripting documentation

I like to use an array map function for this.

Symptom: id_array.map(recordID => ({id: recordID}))

There are a few other unexpected things about your code, but hopefully this will give you enough to work with.

Rose_Haft1
8 - Airtable Astronomer
8 - Airtable Astronomer

That gives the following error:


x: Can't create records: invalid cell value for field 'Symptom'.
Duplicate linked record objects
    at main on line 154

@kuovonne - If it helps, this hard code works:

id_array.push(recordID)

Symptom: [{id: id_array[0]},{id: id_array[1]}],

But I am trying to do this via a loop instead of hardcoding

Sounds like you have a duplicate value in your array.

Hi,

I would recommend to use some variable (for example, name it ‘toCreate’) containing array

[
{fields: {
Client: [{id: clientID}],
Symptom: [{id: {id_array}]}
}]

and then
await table_Output.createRecordsAsync(toCreate);

await is mandatory for async functions
in case or error you can temporary comment record creation and set output for debug reasons:

output.inspect(toCreate)
//await table_Output.createRecordsAsync(toCreate);

but first of all, what function do you need?
into a createrecordasync function? - create single record
or
table_Output.createRecordsAsync - create multiple records

Hi - Perhaps the question wasn’t clear, @Alexey_Gusev

It isn’t a problem with adding one term to different fields, the problem is adding multiple fields where there are multiple linked records in that field.

This hardcode works:
Symptom: [{id: id_array[0]},{id: id_array[1]}]

But I am having trouble looping it or knowing how to map it and add to the rest of the array.

Note, @Alexey_Gusev this code you put did not work:

Symptom: [{id: {id_array}]}

As there are multiple values in the array.

@kuovonne - the scripting allows for multiple values, so the problem is a syntax problem.

@Rose_Haft1 The initial reply from @kuovonne should work. Are you certain that id_array is a string array? I recommend logging it to the console to confirm.

If you confirm that it’s a string array, could you please copy and paste the exact code you’re testing after applying Kuovonne’s solution? I recommend using the preformatted text styling option—the button that looks like </> in the comment editor—to style your code more cleanly.