Try it this way:
function onEdit(e) {
const sh = e.range.getSheet();
if (e.range.columnStart == 7 && sh.getName() == "Daniel") {
if (!e.value) {
e.range.setValue("");
}
else {
if (!e.oldValue) {
e.range.setValue(e.value);
}
else {
if (e.oldValue.indexOf(e.value) < 0) {
e.range.setValue(e.oldValue + '|' + e.value);
}
else {
e.range.setValue(e.oldValue);
}
}
}
}
}
Remember you cannot just run functions like this from a menu or from the script editor. If you're not doing anything that requires permissions then you can run it with a simple trigger. If you're doing operations that require permission then you must pick a name other than onEdit and use an installable trigger.
Try putting this one on a blank Sheet1 and setup column 7 to have a drop down. On changes to column 7 you will be able to see the values in the event object show up in cell A1. And you'll also see when the function is working because it displays a toast in the sheet.
function onEdit(e) {
e.source.toast('entry');
const sh = e.range.getSheet();
sh.getRange(1,1).setValue(JSON.stringify(e));
if (e.range.columnStart == 7 && sh.getName() == "Sheet1") {
if (!e.value) {
e.range.setValue("");
}
else {
if (!e.oldValue) {
e.range.setValue(e.value);
}
else {
if (e.oldValue.indexOf(e.value) < 0) {
e.range.setValue(e.oldValue + '|' + e.value);
}
else {
e.range.setValue(e.oldValue);
}
}
}
}
}
Here's a small animation of what it's doing now.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…