Domanda

I would like to edit a response option instead of adding a new response if the timestamp is already present in the reponse spreadsheet. This is what i have tried.

function trial(event) {

  var email = "xxxx@gmail.com";
  var ss = SpreadsheetApp.getActiveSheet();
  var data = ss.getDataRange().getValues();
  var body = '';

  //Comapring timestamp in each row with the timestamp entered in the form
  var i = 0;
  while(i < data.length) {
    if(data[i][0].toString() ==  event.namedValues['Timstamp'].toString()){
      body += '\n The row number: ' + i;
      data[i][1] = 'ADDDDDDD';
      data[i][2] = event.namedValues['Status'].toString();
      ss.deleteRow(event.range.getRow());
    }
    i++;
  }



  var subject = "Delete Test";
  GmailApp.sendEmail(email, subject, body);

}

I am entering the timestamp in the form as a value(I took care of passing the appropriate timestamp, user need not enter it; it would be prefilled). Now if there is a match, it deletes the new response but does not modify the old one. Can anyone point out my mistake.

È stato utile?

Soluzione

Your script modifies the data array but doesn't write it back to the spreadsheet...that's why you don't see any change in the spreadsheet.

Just add a line after the loop to update the sheet with the appropriate data. I guess it could be something like

ss.getRange(1,1,data.length,data[0].length).setValues(data);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top