Help

Help with script: Update linked record field via api with array of linked record IDs not working.

Solved
Jump to Solution
1118 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Joseph_Roza
8 - Airtable Astronomer
8 - Airtable Astronomer

I've posted the code below.

What am I missing here? I'm trying to update the field 'Parent' with the Parent's record ID when creating records in the 'Child' table, but it says that it cannot accept the value provided...even though it's an array of recordIDs (in this case, just a single one).

I even have a log showing that it provides the correct record ID, which it does.

I appreciate any help anyone is willing to offer.

 

let sourceTable = base.getTable("Parent");
let destinationTable = base.getTable("Child");

let query = await sourceTable.selectRecordsAsync();
let checkedRecords = query.records.filter(record => record.getCellValue("Transfer"));

let recordsToCreate = checkedRecords.map(record => {
   
    // Get the record ID from the source record
    let sourceRecordId = record.id;

    return {
        fields: {
    
            'Name': record.getCellValue('Name'),
            'Parent': [sourceRecordId]  // Pass as an array
        }
    }
});

while (recordsToCreate.length > 0) {
 
    for (let record of recordsToCreate.slice(0, 50)) {
        console.log(`Creating record with sourceRecordId: ${record.fields['Parent'][0]}`);
    }

    await destinationTable.createRecordsAsync(recordsToCreate.slice(0, 50));
    recordsToCreate = recordsToCreate.slice(50);
}

 

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

I think the expected format's `[{id: RECORD_ID}]`, so perhaps try:

 'Parent': [{id: sourceRecordId}]

 

See Solution in Thread

2 Replies 2
TheTimeSavingCo
18 - Pluto
18 - Pluto

I think the expected format's `[{id: RECORD_ID}]`, so perhaps try:

 'Parent': [{id: sourceRecordId}]

 

That was exactly it. I knew it was something simple like that. Thank you so much.