函数错误:范围的起始行太小

时间:2019-10-03 02:34:37

标签: google-apps-script google-sheets

我目前在说我的Google应用脚本代码错误:

范围的起始行太小。 (第48行,文件“ sendEmail”)

我不确定为什么这么小。这些行上升到放置“已发送”字符串值的M。

这是我的代码:

function myFunction(e) {

  var sheet = SpreadsheetApp.openById("1naSWINA8_uxeLUsj0lFntqILyDj2nirb56uvkBel79Y").getSheetByName("CRM Feedback");

  var ss = SpreadsheetApp.getActive().getSheetByName("Form Responses 1");

  var data = sheet.getRange(4, 1, ss.getLastRow(), ss.getLastColumn()).getValues();

  var manager_email = "thomas.hunt@careertrackers.org.au";

  for( var i = 0; i< data.length;i++ ) {

    var timestamp =             data[i][0];
    var requesterEmail =        data[i][1];
    var starRating =            data[i][2];
    var requestCatergory =      data[i][3];
    var description =           data[i][4];
    var label =                 data[i][5];
    var ticketId =              data[i][6];
    var comment =               data[i][7];
    var status =                data[i][8];
    var priority =              data[i][9];
    var office =                data[i][10];

    var check = data[i][11];
    Logger.log(check)

    var checkTimestamp = data[i][0]
    Logger.log(checkTimestamp)


    if(check == false){
      continue;
    } else {


      var subject = "Weekly Timesheet - ";
      var body = "<body>";
      body += "<div>Hi " + comment
      body += "</body>";



      MailApp.sendEmail(manager_email, subject, body, {htmlBody:body}) 

          var sent_string = "sent";
    //error here
    ss.getRange(i, 12).setValue(sent_string)

    if (sent_string){
      return

    }





    }


  }




}

1 个答案:

答案 0 :(得分:1)

documentationrow的{​​{1}}参数接受一个整数,其中行索引以1开头。

Sheet.getRange循环中,您正在传递for作为行,而i以0开头,因此将引发i错误。您应该传递range is too small而不是i + 1作为i参数。

row