-
-
Save pierandrea/3fcccada803ca34c9e09 to your computer and use it in GitHub Desktop.
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); | |
} |
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 |
@2nisi
that is my final code, I'm getting the same #ERROR.
Are you really sure you wrote the correct formula?
function assignEditUrls() {
var form = FormApp.openById('Form Key');
//enter form ID here
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Worksheet Name');
//Change the sheet name as appropriate
var data = sheet.getDataRange().getValues();
var urlCol = 40; // 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(['=HYPERLINK("' + [data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:''] + '","Edit")']);
}
sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls);
}
Is there anything I can do to underestand why the formula is not correct?
Of Course "Form Key" and "Worksheet Name" are correct.
If I use
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
On line 19, I get a working full link.
Thanks, I really don't know what to do to fix that.
@2nisi that is my final code, I'm getting the same #ERROR. Are you really sure you wrote the correct formula?
function assignEditUrls() { var form = FormApp.openById('Form Key'); //enter form ID here
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Worksheet Name');
//Change the sheet name as appropriate
var data = sheet.getDataRange().getValues(); var urlCol = 40; // 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(['=HYPERLINK("' + [data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:''] + '","Edit")']);
} sheet.getRange(2, urlCol, resultUrls.length).setValues(resultUrls); }
Is there anything I can do to underestand why the formula is not correct? Of Course "Form Key" and "Worksheet Name" are correct. If I use
resultUrls.push([data[j][0]?urls[timestamps.indexOf(data[j][0].setMilliseconds(0))]:'']);
On line 19, I get a working full link. Thanks, I really don't know what to do to fix that.
Try to copy the cell with the error message and paste the content to another cell. Do you still receive an error on the new cell? I am using the exact same code and should normally work.
@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....
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.
@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....
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,
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
Of course, I have no idea of what the problem could be.....