Thomas Hunt
Thomas Hunt

Reputation: 13

Function error: The starting row of the range is too small

I am currently getting an error with my google app script code which it is saying:

The starting row of the range is too small. (line 48, file "sendEmail")

I am not to sure why it is to small. The rows go up to M where the "sent" string value is being placed.

here is my code:

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 = "[email protected]";
  
  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
      
    }
    
    
    
    

    }
    
    
  }
  
  
  
  
}

Upvotes: 1

Views: 3778

Answers (1)

Thum Choon Tat
Thum Choon Tat

Reputation: 3090

From the documentation, the row parameter for Sheet.getRange accepts an Integer where the row index starts with 1.

In the for loop, you are passing i as the row and i starts with 0, therefore it is throwing the range is too small error. You should be passing i + 1 instead of i as the row parameter.

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

    ss.getRange(i + 1, 12).setValue(sent_string)

    // code here
}

Upvotes: 2

Related Questions