Help

Appending to a linked record using scripting

Topic Labels: Automations
4069 11
cancel
Showing results for 
Search instead for 
Did you mean: 
ChrisG
4 - Data Explorer
4 - Data Explorer

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

ChrisG_0-1689790620784.png

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 11
Sho
11 - Venus
11 - Venus

Try this

 

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

 

`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

@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.

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}.

ChrisG_0-1689865898815.png

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-...

 

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.

ChrisG
4 - Data Explorer
4 - Data Explorer

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:

ChrisG_0-1689866400270.png

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

 

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.

Sho
11 - Venus
11 - Venus

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.

ChrisG_0-1690228923488.png

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