0

我正在尝试在我的电子邮件通知中添加另一个因素。目前,电子邮件看起来像:9th


姓名

我希望它阅读:

9日


姓名 编号

这些名称来自第 [0] 行,由条件触发。我想在行 [1] 中包含触发条件的数字,这可以在下面我的代码的第一部分中看到。如何让电子邮件包含在行 [1] 中导致行 [0] 中的相应名称也包含在电子邮件中的数字?

任何和所有的帮助表示赞赏!我没有编码背景,但需要把它放在一起上学,所以请尽可能用外行的话回答。

  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<28) || violations >=6 && (adminComment.toString().length<43) || violations >=8 && (adminComment.toString().length<58)){
   Logger.log(adminComment);
     students.push(row[0]);
    }
 });
  return students;
}

function getEmail(admin) {
  var email;
  SpreadsheetApp.getActiveSpreadsheet()
    .getSheetByName("Emails")
    .getRange('A2:B')
    .getValues().
    forEach(function (row) {
     if(row[0] === admin ) {
       email = row[1];
    }
 });
  return email;
}

function printList( students ) {
    students.forEach(function (student) {
     Logger.log(student);
 });

}

function buildEmailBody(header, students) {
  message = header + ": \n";
  count = 0;
    students.forEach(function (student) {
     //Logger.log(student);
     message += student + "\n";
     count++;
 });
 if(count === 0 ) {
   message += "None";
 }
 message += "\n";
  return message;
}

function processSheet(sheetname) {
  email = getEmail(sheetname);
  if( !email ) {
    Logger.log("Email not found for " + sheetname);
    return;
  } 

  const students9 = getViolators(sheetname, 'A3:C');
  const students10 = getViolators(sheetname, 'F3:H');
  const students11 = getViolators(sheetname, 'K3:M');
  const students12 = getViolators(sheetname, 'P3:R');

  emailBody = '';
  emailBody += buildEmailBody("9th Grade", students9);
  emailBody += buildEmailBody("10th Grade", students10);
  emailBody += buildEmailBody("11th Grade", students11);
  emailBody += buildEmailBody("12th Grade", students12);

  // Send Alert Email.
  var subject = sheetname + ' Cell Phone Violations';

  Logger.log("Email: " + email);
  Logger.log("Subject: " + subject);
  Logger.log("Body: \n" + emailBody);
  MailApp.sendEmail(email, subject, emailBody);

}

function CheckStudentViolations() {
 processSheet("Williams (A-Chan)");
 processSheet("Banks (Chan-Gua)");
 processSheet("Britton (Gub-Mars)");
processSheet("Johnson (Mart-Req)");
 processSheet("Cashman (Rer-Vi)");
 processSheet("Garner (Vj-Z)");
processSheet ("Name Not Found in Drop Down")
 processSheet("bodaghi");


}```


4

0 回答 0