I have been trying to change the background color of the cell value based on the STATUS. If the status is OLD FILE then i would like to set the background color of the cell red, and if the status is NEW FILE, i would like to set it into green (as shown in the sample).
Here is the code:
const cells = sheet.getRange("I2:I" + sheet.getLastRow())
const cellValues = cells.getValues()
Logger.log(cellValues)
const newValues = []
var backGrounds = []
cellValues.forEach((row) => {
if (row[0] === "new file") {
newValues.push(['OLD FILE'])
}
else if (row[0] === "OLD FILE" || row[0] === "NEW FILE") {
newValues.push([row[0]])
}
else {
newValues.push(['NEW FILE'])
backGrounds.push(['00ff00'])
}
})
cells.setValues(newValues).setBackground(backGrounds)
}
I have tried using the backGrounds.push(['00ff00'])
and .setBackground(backGrounds)
but it still not changing.
How can i change the the cell background color based on the status?