I’m using a ‘vlookup’ style script below as part of an automation triggered each time a new record is created.
//Substitute "Orders" for table name which contains values
//on which you want to run the vlookup
let mainTable = base.getTable("Litters");
let mainTableRecords = await mainTable.selectRecordsAsync({fields:i"breed_string"]});
//Substitute "Product" for table which contains range to search in
let lookupTable = base.getTable("Breed Landing Pages");
let lookupRangeRecords = await lookupTable.selectRecordsAsync({fields:i"Name"]});
//Replace "Item.barcode" with column name which has the values you want to look up
for (let record of mainTableRecords.records) {
let lookupValue = record.getCellValue("breed_string");
//Replace "Barcode" with column name which is the range to search in
for (let rangeRecord of lookupRangeRecords.records) {
if (rangeRecord.getCellValue("Name") === lookupValue) {
let linkID = rangeRecord.id;
//Replace "Product" with column name from mainTable which should contain the link
await mainTable.updateRecordAsync(record, {
breed_lookup: o{id: linkID}]
});
}
}
}
My aim is to lookup the value just on the record that has been created (rather than all columns as the script currently does) and return a corresponding value from another table.
Can anybody help me in tweaking the code accordingly?