I copied @Justin_Barrett’s script from the below post and modified it for my purpose:
I’m inputting productName (formula field, text formatted) and recordID from the trigger. My tables are Departures with a linked field Product towards the table Products, where the primary field Product matches the productName input.
let DepartureTable = base.getTable("Departures");
let ProductTable = base.getTable("Products");
let ProductsQuery = await ProductTable.selectRecordsAsync();
let config = input.config();
// Find the matching record
let matched = ProductsQuery.records.filter(product => {return product.product === config.productName});
let productRecord;
// If a matching record exists, use it; otherwise make a new record
if (matched.length)
productRecord = matched[0].id;
await DepartureTable.updateRecordAsync(config.recordID, {"Product": [{id: productRecord.id}]});
It seems the query comes up empty with an error “TypeError: Cannot read property ‘id’ of undefined
at main on line 12”. When I enter the following line it will create a new record in products wit the correct primary field name, a duplicate of the existing one.
else
productRecord = await ProductTable.createRecordAsync({"Product": config.productName});
Could some point me towards the error in the query?
