title: getting responseID of latest form submission in google apps
body: <p>I have a google form. Every time it is submitted, the answers go into a google spreadsheet. I am trying to write an app script that triggers every time the form is submitted, and adds an "edit" link in the column to the right of the data from the form. The link itself is easy to generate, google has a method called getEditResponseURL(). (<a href="https://developers.google.com/apps-script/reference/forms/form-response" rel="nofollow">https://developers.google.com/apps-script/reference/forms/form-response</a>)</p>
  
  <p>But everytime I run it, I am getting the error "TypeError: Cannot call method "getResponses" of null."</p>
  
  <p>Here is my code:</p>
  
  <pre><code>function addeditlink(e) {
    // Get the active sheet
    var sheet = SpreadsheetApp.getActiveSheet();
  
    // Get the active row
    var row = sheet.getActiveCell().getRowIndex();
  
    //get the form
    var form = FormApp.getActiveForm();
  
     //get latest form response
    var responses = form.getResponses();
    var lastResponse = responses[responses.length - 1];
  
    //get edit URL
    var editurl = lastResponse.getEditResponseUrl();
  
    //build link
    var editlink = "&lt;a href=\"" + editurl + "\"&gt;Edit&lt;/a&gt;";
  
  //place edit link in column R (index 18)
  if (sheet.getRange(row, 18).getValue() == "") {
      sheet.getRange(row, 18).setValue(editlink);
    }
  }
  </code></pre>
  
  <p>Any help? Thanks!</p>