Feb 26, 2021 02:47 PM
Hey Airtable community,
I am having trouble automating a script that triggers when the quantity field is updated of a new record. The trigger action is that a record is inserted into another table (Inventory Quantities) with the id of the current table (Products) and quantity set to 0.
I had no issues when I set the field type of Product ID to number, but when I switched it to a linked record thats when the trouble started.
Please find the code below as per suggestions and documentation on how to handle linked records:
let ProductsTable = base.getTable("Products");
let QuantityTable = base.getTable("Inventory Quantities");
let query = await ProductsTable.selectRecordsAsync({
sorts: [
{field: "Product ID"},
]
});
let record = query.records[query.records.length-1];
let productID = record.getCellValue("Product ID") + '';
let newRecord = await QuantityTable.createRecordAsync({
"Product": [{id: productID }],
"Quantity": 0
})
This code throws Field “Product” cannot accept the provided value.
What could be causing this issue.
Thanks in advance for you assistance.
Mar 03, 2021 01:09 PM
Hi @Bahle_Makhaya - I think it is this line this is causing issues. record
is a single element from the query.records
array, so you should just be able to record.id
. This can then go into your createRecord call:
let newRecord = await QuantityTable.createRecordAsync({
"Product": [{id: record.id }],
"Quantity": 0
})
Jan 21, 2022 09:23 AM
This should be in the primary docs. Great find!