In this code, I'm trying to create conditional formatting rules depending on the condition sent in another function.
var rule
var rango
var a = []
switch (condition) {
case "Tipo Equipo":
rango = sheet.getRange("K2:K" + fila)
rule = SpreadsheetApp.newConditionalFormatRule()
.whenTextEqualTo("Kit Pediátrico")
.setBackground("#BDE1F2")
.setRanges([rango])
.build()
a.push(rule)
sheet.setConditionalFormatRules(a)
break
case "Tipo Servicio":
rango = sheet.getRange("L2:L" + fila)
rule = SpreadsheetApp.newConditionalFormatRule()
.whenTextEqualTo("Cambio")
.setBackground("#42ECFF")
.setRanges([rango])
.build()
a.push(rule)
sheet.setConditionalFormatRules(a)
break
The problem is that, when I run the function, it only creates the last rule, and the others are deleted by default... What do you suggest?