Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Measuring String Length Other than Zero

I'm trying to set up conditions so it will trigger my function (ultimately an email) when the string length in row 2 is three characters or fewer when the value in row 1 is 4 or more, or if the string length is zero in row 2 and 2 or more in row 1. I originally had it set up to trigger the function if string length in row 2 is zero and row 1 is 2 or more, or when row 2 is 4 or more and row 3 is empty, and my code worked. It looked like this:

function getViolators(sheet, range) {
  var totalViolationsRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet).getRange(range);
  var vals =  totalViolationsRange.getValues();
 // Logger.log(vals[0][0]);

  //vals.forEach()
  const students = [];
  vals.forEach(function (row) {
    var violations = row[1];
    var adminComment = row[2];
    var adminComment2 = row[3];
    if(violations >= 2 && (!adminComment || adminComment.toString().length === 0) || violations >=4 && (!adminComment2 || adminComment2.toString().length === 0) ){
   Logger.log(adminComment);
   Logger.log(adminComment2);
     students.push(row[0]);
    }
 });
  return students;
}

This is my current code, which tries to measure a string length other than zero, and even though I'm not getting an error message, it's not working/measuring code lengths correctly:

function getViolators(sheet, range) {
  var totalViolationsRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet).getRange(range);
  var vals =  totalViolationsRange.getValues();
 // Logger.log(vals[0][0]);

  //vals.forEach()
  const students = [];
  vals.forEach(function (row) {
    var violations = row[1];
    var adminComment = row[2];
    if(violations >= 2 && (!adminComment || adminComment.toString().length === 0) || violations >=4 && (adminComment.toString().length <= 3) ){
   Logger.log(adminComment);
     students.push(row[0]);
    }
 });
  return students;
}

Any help you can offer would be greatly appreciated. I am NOT an experienced coder, just trying to do something for my school.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda