当列中的任何单元格更改为“是”时发送电子邮件 [英] Send email when any cell in column is changed to 'YES'
问题描述
我有一个包含是/否列(电子表格AP)的电子表格,每当该列中的任何值更改时,我都需要发送电子邮件通知。我已经研究出如何在更改特定单元格时发送一个:
I have a spreadsheet with a Yes/No column (column AP) and I need to send an email notification whenever any value within that column is changed. I have worked out how to send one when a specific cell is changed:
function sendNotification(e) {
if("AP4" == e.range.getA1Notation()) {
if(e.value == "YES") {
//Define Notification Details
var recipients = "***********@gmail.com";
var subject = "Update"+e.range.getSheet().getName();
var body = "This cell has changed";
//Send the Email
MailApp.sendEmail(recipients, subject, body);
}
}
}
但是,我需要这样做
然后,我还需要存储其他值以及已更改的行作为变量,以在电子邮件正文中使用。因此,例如,产品名称在B列中,我需要能够访问该名称,以便我的消息显示为 + productName列AP已更改为'是。
I also then need to store other values with the changed row as variables to use within the email body. So for example, the product name is in column B, and I need to be able to access this name so that my message reads something like "Column AP has been changed to 'Yes' for " + productName. Any help would be received very gratefully.
推荐答案
尝试以下操作:
function sendNotification(e){
if(e.range.getColumn()==42 && e.value=='YES'){
var recipients = "***********@gmail.com";
var subject = "Update"+e.range.getSheet().getName();
var body = "This cell has changed";
var valColB=e.range.getSheet().getRange(e.range.getRow(),2).getValue();
MailApp.sendEmail(recipients, subject, body)
}
}
这篇关于当列中的任何单元格更改为“是”时发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!