0

I am new to scripts, but I was able to find a one that uses getEditResponseUrls to insert the edit link from a form into a Google Sheet. I've now been asked to add a second sheet to my spreadsheet that tracks different but related information pulled from a newly-created form (form 2).

I copied and pasted the working 'getEditResponseUrls' code for 1st sheet immediately underneath and changed the form URL and sheet name accordingly. The information is pulling into the second sheet correctly, but the hyperlink is not coming in. I did include the option to edit responses in form 2, so that's not the problem. Can anyone venture a guess as to what my issue may be?

Code - I changed the form URL to protect the innocent

var formURL = 'https://docs.google.com/forms/d/FORM 1URL/viewform';
var sheetName = 'SHEET1';
var columnIndex = 12 ;

function getEditResponseUrls() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('V');
var data = sheet.getDataRange().getValues();
var form = FormApp.openByUrl(formURL);
for(var i = 2; i < data.length; i++) {

if (data[i][0] != '' && data[i][columnIndex-1] == '') {
var timestamp = data[i][0];
var formSubmitted = form.getResponses(timestamp);
if (formSubmitted.length < 1) continue;
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
sheet.getRange(i+1, columnIndex).setValue(editResponseUrl);
}
}
}

var formURL = 'https://docs.google.com/forms/d/FORM 2URL/viewform';
var sheetName = 'SHEET2';
var columnIndex = 12 ;

function getEditResponseUrls() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('SHEET2');
var data = sheet.getDataRange().getValues();
var form = FormApp.openByUrl(formURL);
for(var i = 2; i < data.length; i++) {
if (data[i][0] != '' && data[i][columnIndex-1] == '') {
var timestamp = data[i][0];
var formSubmitted = form.getResponses(timestamp);
if (formSubmitted.length < 1) continue;
var editResponseUrl = formSubmitted[0].getEditResponseUrl();
sheet.getRange(i+1, columnIndex).setValue(editResponseUrl);
}
}
}

I'm now getting an error at line 35 for form 2:

var form = FormApp.openByUrl(formURL);
  • What is the textual error that you are getting? – Rubén Jun 5 '18 at 23:54
0

Each function declaration should have unique names, otherwise only one of the functions will be executed.

It could be a good idea that you spend some time learning JavaScript as Google Apps Script uses it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.