samedi 28 janvier 2017

Google Form If Command Error

I've been trying to code a function for a Google form that will send an email to a particular teacher that is indicated by the form. The problem is that I keep getting an error on a simple if statement. The error says, "Missing ; before statement. (line 29, file "Code")". The code is based on this Google Apps tutorial: http://ift.tt/1RnwY7N. This is what I have right now:

    function sendEmails() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var dataSheet = ss.getSheets()[0];
  var dataRange = dataSheet.getRange(2, 1, dataSheet.getMaxRows() - 1, 4);

  var templateSheet = ss.getSheets()[1];
  var emailTemplate = templateSheet.getRange("A1").getValue();

  // Create one JavaScript object per row of data.
  var objects = getRowsData(dataSheet, dataRange);

  // For every row object, create a personalized email from a template and send
  // it to the appropriate person.
  for (var i = 0; i < objects.length; ++i) {
    // Get a row object
    var rowData = objects[i];

    // Generate a personalized email.
    // Given a template string, replace markers (for instance ${"First Name"}) with
    // the corresponding value in a row object (for instance rowData.firstName).
    var emailText = fillInTemplateFromObject(emailTemplate, rowData);
    var emailSubject = "Lab Visit Report";

  var sheet = SpreadsheetApp.getActiveSheet();
  var data = sheet.getDataRange().getValues();
  for (var i = 0; i < data.length; i++) {
  var teacher = data[i][10];

    If (teacher == "Jake Nabasny") {MailApp.sendEmail("JakeN@school.edu", emailSubject, emailText);}
    else if (teacher == "Dan S") {MailApp.sendEmail("DanS@school.edu", emailSubject, emailText);}

  }
}

I've already made sure that the variables (such as teacher and emailText) contain data. The problem, as far as I can tell, is solely with the if statement. Can anyone please give me an idea of what is going wrong here?

Aucun commentaire:

Enregistrer un commentaire