Reputation: 195
I'm trying to come up with a script that onEdit will get the Row Number for the Checkbox Selected, copy that row number and Set the Value on another sheet on Cell M1 and then send an email automatically, however the Trigger is not occurring on Edit, below my code:
function onEdit(e) {
if(e.range.getSheet().getName() != 'Example') { return; }
if(e.range.columnStart==22 && e.value=="TRUE") {
SpreadsheetApp.getActiveSpreadsheet().getActiveRange().getRow().getSheetByName("Email").range("M1").setValue(row);
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email").activate();
var details = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email").getRange("M1").getValues();
var recipient = "[email protected]";
var subject = "Example for the Number" && details;
var body = "This is an example test";
MailApp.sendEmail(recipient, subject, body);
}
}
Upvotes: 0
Views: 1707
Reputation: 201408
I believe your current situation and your goal as follows.
SpreadsheetApp.getActiveSpreadsheet().getActiveRange().getRow().getSheetByName("Email").range("M1").setValue(row);
, getRow()
returns the row number. So I think that an error occurs at getSheetByName("Email")
. I thought that this might be the reason of your issue.MailApp.sendEmail
is used. In this case, MailApp.sendEmail
cannot be used with the simple trigger. By this, I thought that an error also occurs.
onEdit
from others. Because when onEdit
is installed as the installable trigger, 2 times both the simple trigger and the installable trigger are executing. Please be careful this.isChecked()
method.When above points are reflected to your script, it becomes as follows.
Please copy and paste the following script and install the OnEdit trigger to installedOnEdit()
. When you use this script, please check the checkbox of the column "V" on "Example" sheet.
function installedOnEdit(e) {
var range = e.range;
if (range.getSheet().getName() != 'Example') { return; }
if (range.columnStart == 22 && range.isChecked()) {
var ss = e.source;
var row = range.getRow();
ss.getSheetByName("Email").getRange("M1").setValue(row);
var details = row;
var recipient = "[email protected]";
var subject = "Example for the Number" && details;
var body = "This is an example test";
MailApp.sendEmail(recipient, subject, body);
}
}
Upvotes: 2