I want to add the Edit Response URL of a Google Form to its spreadsheet and tried the code from the link below, but nothing happens. Any idea what's the problem?
https://ctrlq.org/code/20540-edit-form-response-spreadsheet-url
/*
* Written by Amit Agarwal
* Web: digitalinspiration.com
* Email: [email protected]
* 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);
}