'Compare cell to an array and return a value in App script
i am trying to create an app script to compare a cell value to an array, where column D has values (task1, task2... task6), each task has a level 1 or 2, therefore if column D2 has value "task1" then it is L1 and the value is set in the respective row in column O, it seems that I might have made several errors in the way as i am not getting the result i would like, any help would be much appreciated.
function fillValues() {
var spreadsheet = SpreadsheetApp.openById().getSheetByName()
var task = spreadsheet.getRange("D2:D" + spreadsheet.getLastRow())
var taskLevel = spreadsheet.getRange("O2:O" + spreadsheet.getLastRow())
var newRange = []
var newFillValue
task.getValues().map(function(value) {
var L1Tasks = ["task1", "task2", "task3"];
var L2Tasks = ["task4","task5", "task6"];
for (var i = 0; i < L1Tasks.length; i++){
if (value[0]==L1Tasks[i]) {
newFillValue="L1"
newRange.push([newFillValue]) }
else { newFillValue="L2" newRange.push([newFillValue]) }
}
})
taskLevel.setValues(newRange)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
