Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!