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.