문제

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.

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top