Last active
September 9, 2024 06:46
-
-
Save pierandrea/3fcccada803ca34c9e09 to your computer and use it in GitHub Desktop.
Google Apps Script code to add Google Form edit response links to 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
function assignEditUrls() { | |
var form = FormApp.openById('yourFormKey'); | |
//enter form ID here | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('yourWorksheetName'); | |
//Change the sheet name as appropriate | |
var data = sheet.getDataRange().getValues(); | |
var urlCol = ; // 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(responses[i].getEditResponseUrl()); | |
} | |
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); | |
} |
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
Copy the code above. | |
Paste it in the Google Sheet where you want to collect the edit response links. | |
Change the following parameters: | |
line 2 - Google Form ID number; | |
line 5 - Destination Worksheet name; | |
line 9 - Column number where edit response links should be collected; | |
Save and run script. | |
Check that edit response links are collected in the right column in your destination Sheet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried doing this in the spreadsheet where my form responses are being put and I can't get it to populate. When I run it I don't get any error messages (execution started and completed) but it doesn't show up in my spreadsheet. Can someone help me troubleshoot this?
As a site note, what does the sheet name refer to? I've tried it both ways and neither worked but is it the file name (top left) or the tab name (bottom left)?
My spreadsheet: This should be populating in column BG