Multiple selection in single Dropdown

Viewed 54

I found this code on reddit that works quite well. Anyway, when I try to delete the information that I completed with the dropdown, or modify something, an undefined value shows up and I can not delete it. How could I do that?

Code:

function onEdit(e){
  if(e.range.columnStart != 6 || e.oldValue == undefined) return;
  e.range.setValue(e.oldValue+" | "+e.value);
}

Screenshot:

Besides, when more than 1 option is added on my cell, an 'invalid' message shows up. How could I delete it? It's a default config from the Data Validation. invalid message

1 Answers

So far your code snippet works on mine properly. (I can't seem to replicate your issue)

But for you, it isn't (that I am not sure). Try to include the condition where e.value is null (that happens when you delete the cell value). Your code should look like this.

Code:

function onEdit(e){
  if(e.range.columnStart != 6 || e.oldValue == null || e.value == null) return;
  e.range.setValue(e.oldValue+" | "+e.value);
}

Note:

  • Try to log the values before comparing them in a condition. It's true that in a == sense, null and undefined are the same as both of them return FALSE, but they have different types. If you have used ===, then they are not equal.

  • If the cell is deleted (as you can see on the image below), both oldValue and value becomes null.

Cloud logs (blank -> yes -> no -> delete cell):

output

Related