Jul 19, 2023 11:21 AM
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:
Jul 19, 2023 05:15 PM
Try this
'Worksheet: BOM': [{ id: record.id }],
Jul 19, 2023 08:31 PM
`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
Jul 20, 2023 03:38 AM
@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.
Jul 20, 2023 08:13 AM
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:
Jul 20, 2023 08:16 AM
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.
Jul 20, 2023 08:20 AM - edited Jul 20, 2023 08:21 AM
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.
Jul 20, 2023 08:26 AM
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.
Jul 20, 2023 06:55 PM
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})});
Jul 24, 2023 01:02 PM
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.