Add the Edit Response URL of Google Forms in Google Sheets

This Google Apps Script code will insert the Form Edit Response URL to the Google Spreadsheet when a new Google Form is submitted. The response URL is added to the same spreadsheet that is collecting the responses for the Google Form.

The code is inserting the raw link here but you can use the built-in HYPERLINK() formula to create a clickable hyperlink inside the spreadsheet cell. The script function can also be integrated with the Google Shortener API (or Bitly) to insert a short URL that is easier to copy-paste and share.

/*
 * Written by Amit Agarwal
 * Web: digitalinspiration.com
 * Email: amit@labnol.org
 * MIT License
 */

// Create the Form Submit Trigger
function createFormTrigger() {
  var triggerName = 'addFormResponseUrl';
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  ScriptApp.newTrigger(triggerName).forSpreadsheet(spreadsheet).onFormSubmit().create();
}

function addFormResponseUrl(e) {
  // Get the Google Form linked to the response
  var responseSheet = e.range.getSheet();
  var googleFormUrl = responseSheet.getFormUrl();
  var googleForm = FormApp.openByUrl(googleFormUrl);

  // Get the form response based on the timestamp
  var timestamp = new Date(e.namedValues.Timestamp[0]);
  var formResponse = googleForm.getResponses(timestamp).pop();

  // Get the Form response URL and add it to the Google Spreadsheet
  var responseUrl = formResponse.getEditResponseUrl();
  var row = e.range.getRow();
  var responseColumn = 10; // Column where the response URL is recorded.
  responseSheet.getRange(row, responseColumn).setValue(responseUrl);
}

Please note that anyone who has access to this unique Form Response Edit URL can change the form response. The getEditResponseUrl() method will return the URL to edit a response that has already been submitted, even if the Form.setAllowResponseEdits(enabled) setting is disabled.

Also, you should always get the URL of the linked Google Form via the active sheet and not the active spreadsheet as there could multiple forms associated with the same Google Spreadsheet.

Amit Agarwal

Amit Agarwal

Google Developer Expert, Google Cloud Champion

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.

Amit has developed several popular Google add-ons including Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

0

Awards & Titles

Digital Inspiration has won several awards since it's launch in 2004.

Google Developer Expert

Google Developer Expert

Google awarded us the Google Developer Expert award recogizing our work in Google Workspace.

ProductHunt Golden Kitty

ProductHunt Golden Kitty

Our Gmail tool won the Lifehack of the Year award at ProductHunt Golden Kitty Awards in 2017.

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional (MVP) title for 5 years in a row.

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator title recognizing our technical skill and expertise.

Email Newsletter

Sign up for our email newsletter to stay up to date.

We will never send any spam emails. Promise.