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 |
bobbyburns
commented
Feb 6, 2023
via email
Please remove me from this thread. I have no relationship to this group. I
think you have entered the wrong email.
…On Mon, Feb 6, 2023, 4:56 AM Eris Sako ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
@2nisi <https://github.com/2nisi> If I copy the cell with the error
message and paste the content to another cell, I got the same #ERROR
This is the code:
resultUrls.push(['=HYPERLINK("' +
[data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:''] +
'","Edit")']);
Are you really sure i didn't make any syntax error? On the top, you can
see the content of che cell as result of the code....
[image: Screenshot_286]
<https://user-images.githubusercontent.com/77392910/216761298-262d3e4a-764f-4e45-b6d9-994d75695b43.jpg>
That is really wierd because if in an empty cell I write a simple correct
formula like
=HYPERLINK("www.google.com","Edit")
The result is always a #ERROR (Formula parse error), even if everything
seems to be correct.
EDIT: I guess i've found the solution:
https://support.google.com/docs/thread/126991179/hyperlink-function-doesn-t-work?hl=en
I have modified the formula to:
resultUrls.push(['=HYPERLINK("' +
[data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:''] +
'"; "Edit")']);
Now everything works.
Ugh!! this stupid convection thing! Didn't even think about this. I'm glad
you figure it out.
Best,
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/3fcccada803ca34c9e09#gistcomment-4461395> or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEWWEOMBFKJL5XDGCQ3EO33WWDKETBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZDANJRHE2TMMVHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
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)?
function assignEditUrls() {
var form = FormApp.openById('1CTdJNu9_goN5lLbmQeHmeFySUfQLTg-SYp2rGpfCiD8');
//enter form ID here
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1");
var data = sheet.getDataRange().getValues();
var urlCol = 59; // 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);
}
My spreadsheet: This should be populating in column BG
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment