Nov 01, 2021 06:12 PM
Hi - I am new to Script, hoping someone can help me have this function return an array or values rather then just one.
EX) Zip code 10001 exist in multiple cells in “ZIP” and was hoping to return all values associated with 10001, not just one value.
//Substitute “Us Enterprise” for table name which contains values
//on which you want to run the vlookup
let mainTable = base.getTable(“US Enterprise”);
let mainTableRecords = await mainTable.selectRecordsAsync();
//Substitute “ZipCodeData” for table which contains range to search in
let lookupTable = base.getTable(“ZipCodeData”);
let lookupRangeRecords = await lookupTable.selectRecordsAsync();
//Replace "Zip Code " with column name which has the values you want to look up
for (let record of mainTableRecords.records) {
let lookupValue = record.getCellValue("Zip Code");
//Replace "Name" with columnn name which value should be returned
for (let rangeRecord of lookupRangeRecords.records) {
if (rangeRecord.getCellValue("Zip") === lookupValue) {
let returnValue = rangeRecord.getCellValue("Name");
//Replace "Carrier" with update value
await mainTable.updateRecordAsync(record, {
"Carrier": returnValue
});
}
}
}
Nov 02, 2021 09:45 AM
Welcome to the community, @Britt_Givens! :grinning_face_with_big_eyes: I recommend finding a good JavaScript reference and playing a bit on your own if you’re interested in learning scripting. To adapt this script based on what you described will require only a few additions:
returnValue
, you would append the value to this array using the .push()
method.
for...of
loop, and only execute if the loop ended with a non-empty array..join()
method on the array to convert it into a comma-separated item string to insert into the desired field.If you need more guidance after taking a crack at it on your own, just holler!