Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

638
Vistas
Why aren't my IF conditions being met? (checkbox.isChecked(), and checkbox == true methods not working)

I'm attempting to apply borders to cells conditionally via apps script, but my code is not registering the two (obviously met) conditions. Looking for a logic and syntax check <3

Sheet: stackoverflow noobs can't attach images so here's a link

Code:

function doBorders() {
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let sss = ss.getActiveSheet();
  let doBorder = sss.getRange("A5");
  let checkBox = sss.getRange("B5");
  let checkState = checkBox.isChecked();
    let bRow1 = sss.getRange("A1:B1");
    let bRow2 = sss.getRange("A2:B2");
    let bRow3 = sss.getRange("A3:B3");

  if (doBorder == "Do Borders:" && checkState == true) {
    bRow1.setBorder(false, false, true, false, false, false,'Black', SpreadsheetApp.BorderStyle.SOLID);
    bRow2.setBorder(false, false, true, false, false, false,'Black', SpreadsheetApp.BorderStyle.SOLID);
    bRow3.setBorder(false, false, true, false, false, false,'Red', SpreadsheetApp.BorderStyle.SOLID);
    Logger.log('Conditions met. Borders added.');

    } else
      bRow1.setBorder(false, false, false, false, false, false);
      bRow2.setBorder(false, false, false, false, false, false);
      bRow3.setBorder(false, false, false, false, false, false);
      Logger.log('Conditions not met. No borders.');
}

I've tried both checkBox == true and checkState == true. Same result.

Execution Log: "Conditions not met. No borders."

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

let checkBox = sss.getRange("B5") gets a Range object, which is different from the value in that cell. To test the value, use Range.getValue(), like this:

  const checkBox = sss.getRange('B5');
  const checkBoxValue = checkBox.getValue();
  if (checkBoxValue === true) {
    // do sfuff...
  } else {
    // do other stuff...
  }

Also observe the { curly braces } after the else.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda