Jan 26, 2022 06:29 AM
Hello the community,
I would like to add a return value condition in the vlookup script depending on another column containing a specific text.
your support is really appreciate.
Thank you
Here my current script that I would like to improve:
let mainTable = base.getTable(“Inscriptions”);
let mainTableRecords = await mainTable.selectRecordsAsync();
let lookupTable = base.getTable(“Ateliers”);
let lookupRangeRecords = await lookupTable.selectRecordsAsync();
for (let record of mainTableRecords.records) {
let lookupValue = record.getCellValue(“Promo”);
for (let rangeRecord of lookupRangeRecords.records) {
if (rangeRecord.getCellValue("Promo") === lookupValue) {
if (“new column”) is containing this specific text "A1"
let returnValue = rangeRecord.getCellValue(“Date”);
await mainTable.updateRecordAsync(record, {
"Atelier 3": returnValue
});
}
}
}
Jan 27, 2022 05:14 PM
HI.
your condition will be like
if (someRecord.getcellValue(‘new_column’).includes(‘sometext’))
if you new column type is not a regilar string (e.g. it’s a link, lookup, single/multi select), use getcellValueAsString
Jan 28, 2022 11:23 AM
Hello Alexy,
thanks for your feedback. it works but issue I have now is concerning the return value.
By this code:
let mainTable = base.getTable(“Questionnaire”);
let mainTableRecords = await mainTable.selectRecordsAsync();
let lookupTable = base.getTable(“Participants”);
let lookupRangeRecords = await lookupTable.selectRecordsAsync();
for (let record of mainTableRecords.records) {
let lookupValue = record.getCellValue(“Adresse e-mail”);
for (let rangeRecord of lookupRangeRecords.records) {
if (rangeRecord.getCellValue("Adresse e-mail") === lookupValue) {
let returnValue = rangeRecord.getCellValueAsString("Nom de la promotion");
await mainTable.updateRecordAsync(record, {
"nomdelapromo": returnValue[0]
});
}
}
}
my return value is only the number “7” instead to “7-201020-PM”. Only first letter is considered.
is there any reason of ?
Best regard
Jan 28, 2022 11:36 AM
add line to debug, and show output
if (rangeRecord.getCellValue(“Adresse e-mail”) === lookupValue) {
let returnValue = rangeRecord.getCellValueAsString(“Nom de la promotion”);
output.inspect(rangeRecord.getCellValue(“Nom de la promotion”))
Jan 29, 2022 06:55 AM
here the output
(1) [Object]
:arrow_forward: 0: Object
:arrow_forward: linkedRecordIds: Array(1)
:arrow_forward: valuesByLinkedRecordId: Object
:arrow_forward: (1) [Object]
:arrow_forward: 0: Object
:arrow_forward: linkedRecordIds: Array(1)
:arrow_forward: valuesByLinkedRecordId: Object
:arrow_forward: (1) [Object]
:arrow_forward: 0: Object
:arrow_forward: linkedRecordIds: Array(1)
:arrow_forward: valuesByLinkedRecordId: Object
:arrow_forward: (1) [Object]
:arrow_forward: 0: Object
:arrow_forward: linkedRecordIds: Array(1)
:arrow_forward: valuesByLinkedRecordId: Object
:arrow_forward: (1) [Object]
:arrow_forward: 0: Object
:arrow_forward: linkedRecordIds: Array(1)
:arrow_forward: valuesByLinkedRecordId: Object
:arrow_forward: (1) [Object]
:arrow_forward: (1) [Object]
:arrow_forward: (1) [Object]
:arrow_forward:
Jan 30, 2022 11:56 AM
Hi,
you should expand it, find which value is different from expected and analyse - why.