Form Google Script Prevent Duplicates

梦想的初衷 提交于 2019-12-01 02:01:56

This won't prevent a Google Form from getting submitted with duplicate values in the first place, but I think what you want will look some thing like...

function updateExisting() {
  var ss = SpreadsheetApp.getActiveSpreadsheet(),
      s = ss.getSheetByName('Sheet1'),
      lastRow = s.getLastRow(),
      lastValues = s.getRange('A'+lastRow+':E'+lastRow).getValues(),
      name = lastValues[0][0],
      allNames = s.getRange('A2:A').getValues(), 
      row, len;

  // TRY AND FIND EXISTING NAME
  for (row = 0, len = allNames.length; row < len - 1; row++)
    if (allNames[row][0] == name) {
      // OVERWRITE OLD DATA
      s.getRange('A2').offset(0, 0, row, lastValues.length).setValues([lastValues]);
      // DELETE THE LAST ROW
      s.deleteRow(lastRow);
      break;}
}

This has to be triggered by the on Form Submit trigger inside your Sheet.

Docs can be overwhelming. They typically just do a 1 or 2 line examples, although if you run through all the tutorials there's a lot more finished examples. It's more on the developers to make these types of scripts.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!