0

I am able to add a timestamp in column 5 using a conditional when I'm comparing the column to a number, but what I am actually trying to do is add a stamp to the corresponding cell in column 5 if a cell in column 1 is checked as TRUE. When the box is checked, the corresponding cell in column 5 never displays the timestamp:

function onEdit(e) {
  var attendanceSheet = e.source.getActiveSheet();
  var row = e.range.getRow();
  var col = e.range.getColumn();

  if(col === true){
    attendanceSheet.getRange(row,5).setValue(new Date());    
  }
  else{
    attendanceSheet.getRange(row,5).setValue("");

  }
}

enter image description here

1
0

Replace

if(col === true){

...with:

if (e.value === 'TRUE') {

To get a truly blank value instead of a zero-length text string, replace

.setValue("")

...with:

.setValue(null)

This makes a difference with functions like count() and isblank().

3
  • Thank you. I have a follow-up question. How can I use isBlank() method in combination with e.value to detect if a cell is actually blank/empty or not. If I need to officially ask this question by posting it, let me know, and I will. Jul 28 at 17:59
  • Please post a new question, and make sure that you describe the problem rather than discussing e.valueet al. Be clear what you mean by "cell is actually blank/empty", i.e., do you want the behavior that matches that of isblank(A1) or the behavior that matches that of not(not(len(A1))). Jul 28 at 19:54
  • OK, thanks. I will rephrase and post the question. Jul 29 at 17:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.