Google-sheets – Script does not trigger on FormSubmit

google sheetsgoogle-apps-script

I am trying to remove older duplicate form responses based on a column using the following code.

The credit for the code goes to:
http://www.jacorre.com/tutorial/remove-duplicate-rows-google-spreadsheets/

The code in my script is:

 function removeDuplicates() {
 var ss = SpreadsheetApp.getActiveSpreadsheet(),
     responses = ss.getSheetByName('Name of Source Sheet'),
     range = responses.getDataRange(),
     numRows = range.getNumRows()-1,
     data = range.getValues(),
     columnHeadings = [data[0]],
     newData = [];
 for (var i=numRows; i>0; i--) {
  var row = data[i],
      duplicate = false;
  for (var j in newData) {
   if (row[4] == newData[j][4]) {
    duplicate = true;
   }
  }
  if (!duplicate) {
   newData.push(row);
  }
 }
 var final = ss.getSheetByName('Name of Destination Sheet');
 if (!final) {
  var final = ss.insertSheet('Name of Destination Sheet');
 } 
 final.clearContents();
 final.getRange(1,1,1,columnHeadings[0].length).setFontWeight('bold').setValues(columnHeadings);
 final.getRange(2, 1, newData.length, newData[0].length).setValues(newData);
}

This has been set to trigger on Form Submit. It works well on new form submissions.

However, when an existing response is edited using 'Form Edit URL' from:
Show URL used to edit responses from a Google Form in a Google Spreadsheet by using a script
the values are not updated into the new sheet.

But if the function is run manually the updated row is updated to the new sheet.

How can I sort this problem? Any help will be appreciated. Thank you.

Best Answer

I just did a test and found that the on form submit event it's not being triggered when a response is edited.

I'm not sure if the on form submit trigger is working as intended, if the above is due to a bug or to a glitch. To be sure, post an issue to the Google Apps Script Issue Tracker.

As a workaround, instead of using the on form submit event, use another way to run your script, like a time-drive trigger.

References