Skip to main content
Solved

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

  • June 27, 2023
  • 2 replies
  • 92 views

Forum|alt.badge.img+21

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); }

 

Best answer by TheTimeSavingCo

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

'Parent': [{id: sourceRecordId}]

 

2 replies

TheTimeSavingCo
Forum|alt.badge.img+31

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

'Parent': [{id: sourceRecordId}]

 


Forum|alt.badge.img+21
  • Author
  • June 27, 2023

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.