Last active
June 24, 2020 12:59
-
-
Save ooobo/a3d60d9d2c4a9fdf5f72 to your computer and use it in GitHub Desktop.
put edit response urls for google form in linked spreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// install as a google script linked to the form, not the spreadsheet. must add a trigger to run assignEditUrls() on form submit. | |
// benefit of linking to the form is that copying the spreadsheet will copy the spreadsheet, form and script. | |
function assignEditUrls() { | |
var form = FormApp.getActiveForm(); | |
var ss = SpreadsheetApp.openById(form.getDestinationId()); | |
var sheet = ss.getSheets()[0]; | |
var data = sheet.getDataRange().getValues(); | |
var urlCol = 2; // column number where URL's should be populated; A = 1, B = 2 etc | |
var responses = form.getResponses(); | |
var timestamps = [], urls = [], resultUrls = []; | |
for (var i = 0; i < responses.length; i++) { | |
timestamps.push(responses[i].getTimestamp().setMilliseconds(0)); | |
urls.push('=HYPERLINK("' + responses[i].getEditResponseUrl() + '", "edit")'); | |
} | |
for (var j = 1; j < data.length; j++) { | |
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']); | |
} | |
sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls); | |
} |
It's been a few years since use, but just ran it again on the old spreadsheet and worked fine - no issues. The "edit" in this line:
urls.push('=HYPERLINK("' + responses[i].getEditResponseUrl() + '", "edit")');
is just a bit of text to hyperlink. You need the = operator at the beginning to indicate it is a formula. Can you paste what you get in the hyperlink cell?
I found error in syntax of the function HYPERLINK, and the solution is turn the comma by semicolon:
(...) + ' " ; "edit")');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I tried but the cell with the HYPERLINK shows an ERROR message. It seems that is because the "=" operator at the beginning. Also the "edit" word at the end, between "" seems wrong.