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 is a web geek, solo entrepreneur and loves making things on the Internet. Google recently awarded him the Google Developer Expert and Google Cloud Champion title for his work on Google Workspace and Google Apps Script.

Awards & Recognition

Google Developer Expert

Google Developer Expert

Google awarded us the Developer Expert title recogizing our work in Workspace

ProductHunt Golden Kitty

ProductHunt Golden Kitty

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

Microsoft MVP Alumni

Microsoft MVP Alumni

Microsoft awarded us the Most Valuable Professional title for 5 years in a row

Google Cloud Champion

Google Cloud Champion

Google awarded us the Champion Innovator award for technical expertise

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

We will never send any spam emails. Promise 🫶🏻