how are you?
I’m encountering an unexpected issue with Apps Script. I’m developing a script that should lock a column when the value of a dropdown menu in Google Sheets changes. After researching online, I found out that the main function should be named onEdit(e) to capture any changes in the sheet. My problem is that part of the code within onEdit is not executing, and I can’t figure out why.
Here’s the code I’m using:
function onEdit(e) {
SpreadsheetApp.getActiveSpreadsheet().toast('entre!');
if (!e) {
Logger.log("Function not triggered by edit");
return;
}
Logger.log("Edit detected");
var sheet = e.source.getActiveSheet();
var range = e.range;
if (sheet.getName() === "ATTN" && range.getA1Notation() === "M2") {
Logger.log("Dropdown menu changed");
var selectedOption = range.getValue();
if (selectedOption === "Yes") {
handleYesOption();
} else if (selectedOption === "No") {
handleNoOption();
}
}
SpreadsheetApp.getActiveSpreadsheet().toast('sali!');
}
The only part that seems to execute are the toast notifications, but the rest of the code doesn’t show messages in the execution log or make changes to the sheet. Does anyone have any idea why this might be happening?
At first, I tried various approaches and added the code gradually. Initially, I only included the first toast. I then added the second toast in an attempt to force the execution of the code and see if that would resolve the issue.