Skip to main content

Appending to a linked record using scripting


Forum|alt.badge.img+4
  • Known Participant
  • 10 replies

I am using an automation that uses a script to append a record to another table's linked field. My code is shown below.

This is not working however, as the record.getCellValue('Worksheet: BOM") is returning an array that has the format ("string") instead of the format (id: "String"). Is there any way to fix this?

This is my error message:

No overload matches this call.
The last overload gave the following error.
Property 'id' is missing in type 'readonly { id: string; name: string; }[]' but required in type '{ id: string; }'.(2769)
env.22.d.ts(5964, 43): 'id' is declared here.
env.22.d.ts(5959, 5): The last overload is declared here.

11 replies

Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • July 20, 2023

Try this

 

'Worksheet: BOM': [{ id: record.id }],

 


TheTimeSavingCo
Forum|alt.badge.img+28

`record.getCellValue('Worksheet: BOM')` returns an array.  You need to push the new ID into that array, and then use the updated value in your updateRecordAsync action


ScottWorld
Forum|alt.badge.img+33
  • Brainy
  • 8759 replies
  • July 20, 2023

@ChrisG You don’t need to use a script to append linked records to a linked record field. You can use Airtable’s normal “Update Records” automation action. You just need to insert the new value, follow it by a comma, and then insert the original field afterwards.


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • 10 replies
  • July 20, 2023
TheTimeSavingCo wrote:

`record.getCellValue('Worksheet: BOM')` returns an array.  You need to push the new ID into that array, and then use the updated value in your updateRecordAsync action


The `record.getCellValue('Worksheet: BOM')` returns an array of the value " {id: string; name: string;}[] while I am only trying to push a ID into that array. Additionally, the updateRecordAsync action only accepts the object of {id: string}, which is not what the record.getCellValue returns. How do I get an array of only {id: string} instead of {name: string}.

Additionally, @ScottWorld  I have tried already to use simply automations: however, it has not worked for me. I tried to resolve this problem here: 

https://community.airtable.com/t5/automations/linking-several-records-to-a-single-record-in-another-table/td-p/156226

 


ScottWorld
Forum|alt.badge.img+33
  • Brainy
  • 8759 replies
  • July 20, 2023

Your automation is failing because you're not giving it a valid Record ID where it asks for Record ID. You can only feed it one Record ID at a time... you can't give it a list of Record ID's. You would need to use a repeating group to do what you want to do.


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • 10 replies
  • July 20, 2023
ScottWorld wrote:

Your automation is failing because you're not giving it a valid Record ID where it asks for Record ID. You can only feed it one Record ID at a time... you can't give it a list of Record ID's. You would need to use a repeating group to do what you want to do.


Correct me if I am mistaken, but I think the updateRecordAsync accepts multiple ID's if you push them through an array. This is on the airtable developers wiki:

I tried to mimic their code, however it does not work for me.

 


ScottWorld
Forum|alt.badge.img+33
  • Brainy
  • 8759 replies
  • July 20, 2023

I was referring to your post at the other link. You can't use Airtable's native automations for what you want to do unless you use a repeating group. I don't know scripting, so I can't help you there. But you can do everything you want natively with Airtable's native automations. You don't need to write a script.


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • July 21, 2023

If you generate a new array like this code, you can write record links.

let bomIDs = []; record.getCellvalue('Worksheet: BOM').forEach((value) => {bomIDs.push({id: value.id})});

 


Forum|alt.badge.img+4
  • Author
  • Known Participant
  • 10 replies
  • July 24, 2023
Sho wrote:

If you generate a new array like this code, you can write record links.

let bomIDs = []; record.getCellvalue('Worksheet: BOM').forEach((value) => {bomIDs.push({id: value.id})});

 


This works but I am not able to use the updateRecordAsync function as I am getting this error.

I assume I have to cast it to an array of type {id: string} but I do not know how to do that.

 


Forum|alt.badge.img+19
  • Inspiring
  • 560 replies
  • July 24, 2023

The object must be written according to the "Cell write format" on this page.
Cell values & field options - Airtable Scripting

Since the bomIDs are as formatted, you can be updated this way.

 

await table.updateRecordAsync(inputConfig.estRecordId[0],{ 'Worksheet: BOM' : bomIDs, })

 

 

 


Forum|alt.badge.img+2
  • New Participant
  • 1 reply
  • November 16, 2023
ScottWorld wrote:

@ChrisG You don’t need to use a script to append linked records to a linked record field. You can use Airtable’s normal “Update Records” automation action. You just need to insert the new value, follow it by a comma, and then insert the original field afterwards.


Hey Scott, I'm getting this to work on string fields, but not for linked records. Not sure why it's different, but it is  not working for linked records.


Reply