Store and Increment a value by one on every new Google Form submission
<p>When a customer completes a form, I want a new ticket number to be created and sent in an email. </p>

<p>The first error:</p>

<blockquote>
  <p>"cannot read property "range" from undefined (line 9, file "Code")</p>
</blockquote>

<p>and then, on lines 11, 13, and 21, I have some code to control a ticket counter to generate a unique ticket number each time the form is submitted. When I ran 2 test forms through the system, the ticket number did not populate and the counter variable did not change.</p>

<pre><code>function onFormSubmit(e) {

  var activateSheet = SpreadsheetApp.getActiveSpreadsheet();

  SpreadsheetApp.setActiveSheet(activateSheet.getSheetByName('Form Responses 1'));

  var sheet = SpreadsheetApp.getActiveSheet();

  var row = e.range.getRowIndex(); *** line 9***

  var ticketCounter = 100; ***line 11***

  var ticketNumber = "FCB" + ticketCounter; ***line 13***

  var etrolControlsServiceEmail = "controls-service@etrol.net";

  var timestamp = sheet.getRange(row, 1).getValues();

  var ticketNumberLocation = sheet.getRange(row, 2);

  ticketNumberLocation.setValue(ticketNumber); ***line 21***

  var location = sheet.getRange(row, 3).getValues();

  var reportedBy = sheet.getRange(row, 4).getValues();

  var customerEmailAddress = sheet.getRange(row, 5).getValues();

  var priority = sheet.getRange(row, 6).getValues();

  var customerIssue = sheet.getRange(row, 7).getValues();

  var subject =  "An issue has been reported at " + location + " " + timestamp + " " + "Ticket Number " + ticketNumber;

  var emailBody = "To: Envirotrol Controls Service Department " + "\nRE: Issue reported at " + location + "." + "\n\nAn issue has been reported  at " + location + ". Please see the details below:" + "\n\nTicket Number: " + ticketNumber + "\nLocation: " + location + "\nReported By: " + reportedBy + "\nPriority Level: " + priority + "\nIssue: " + customerIssue;

  MailApp.sendEmail(customerEmailAddress + ", " + etrolControlsServiceEmail, subject, emailBody);

  ticketCounter += 1};
</code></pre>