0
votes

I have a google spreadsheet with two google forms (form responses 1 and 2) being used for registration. I have a sheet called 'Registered' in which I need the new data entered in either form responses to be automatically copied to the 'registered' sheet onForm Submit. I created two functions below and setup triggers but it doesn't work. I'm a novice with this; Please kindly assist me with this. Thanks in advance

 function copyRowsFromForm2(){
      var responses = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 2");
      var projects =  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Registered");
      var lastrow = responses.getLastRow();
      var col = responses.getLastColumn();
      var row = responses.getRange(lastrow, 1, 1, col).getValues();
    
      projects.appendRow(row[0]);
      //copyValuesOnly(copyFromRange, copyToRangeStart);
    }
    
    
    function copyRowsFromForm1(){
      var responses = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1");
      var projects =  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Registered");
      var lastrow = responses.getLastRow();
      var col = responses.getLastColumn();
      var row = responses.getRange(lastrow, 1, 1, col).getValues();
    
      projects.appendRow(row[0]);
      //copyValuesOnly(copyFromRange, copyToRangeStart);
    }
1
Don't use lastRow. Use the values from the onFormSubmit event object If you get multiple form submission very quickly then lastRow will be the wrong row.Cooper

1 Answers

1
votes

try this:

function onFormSubmit(e) {
  const ss=SpreadsheetApp.getActive();
  ss.getSheetByName('Registered').appendRow(e.values);
}

e is the destination for the event object when the trigger fires the function. So you can't run the function without supplying the event object.

Reference: