Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gregonarash/2ec997dd2b852130de5b6c9f8d4fcfd3 to your computer and use it in GitHub Desktop.
Save gregonarash/2ec997dd2b852130de5b6c9f8d4fcfd3 to your computer and use it in GitHub Desktop.
//Substitute "Orders" for table name which contains values
//on which you want to run the vlookup
let mainTable = base.getTable("Orders");
let mainTableRecords = await mainTable.selectRecordsAsync({fields:["Item.barcode"]});
//Substitute "Product" for table which contains range to search in
let lookupTable = base.getTable("Products");
let lookupRangeRecords = await lookupTable.selectRecordsAsync({fields:["Barcode"]});
//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("Item.barcode");
//Replace "Barcode" with column name which is the range to search in
for (let rangeRecord of lookupRangeRecords.records) {
if (rangeRecord.getCellValue("Barcode") === lookupValue) {
let linkID = rangeRecord.id;
//Replace "Product" with column name from mainTable which should contain the link
await mainTable.updateRecordAsync(record, {
Product: [{id: linkID}]
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment