[英]Send email from Google Sheet when cell is certain value
Here is an example of the sheet I am trying to make this work for: https://docs.google.com/spreadsheets/d/1M79ki9QVRkfkwy1uWyNAVddeyPpcvqDppi3Et-b-cLw/edit?usp=sharing以下是我正在尝试为其工作的工作表示例: https : //docs.google.com/spreadsheets/d/1M79ki9QVRkfkfkwy1uWyNAVddeyPpcvqDppi3Et-b-cLw/edit?usp=sharing
The goal is that an email is sent when column I is greater than 2 and column K is null.目标是当 I 列大于 2 且 K 列为空时发送电子邮件。 Column I is a count formula based on columns CH, which are manually filled in.
第 I 列是基于 CH 列的计数公式,这些列是手动填写的。
Here is the script I have, but it doesn't seem to be working:这是我的脚本,但它似乎不起作用:
function sendEmail() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName("Workable");
var listing_id = sheet.getRange("B:B").getValues();
var flag_count = sheet.getRange("I:I").getValues();
var action_type = sheet.getRange("K:K").getValues();
var subject = 'New Listing Flagged';
var message = 'Listing' + listing_id + 'has been flagged. Please resolve ASAP in the QA Google Sheet. Thank you!';
var email_address = 'allyson@hipcamp.com';
if (flag_count > 2 && action_type == ""){MailApp.sendEmail(email_address, subject, message)}
}
What do I need to change to make it work?我需要改变什么才能使它工作?
I got your latest code in the sample sheet.我在示例表中找到了您的最新代码。 Since you've decided to use onEdit trigger, you need to use the installable onEdit trigger because you are using
MailApp.sendEmail()
service which requires authorization.由于您已决定使用 onEdit 触发器,因此您需要使用可安装的 onEdit 触发器,因为您使用的是需要授权的
MailApp.sendEmail()
服务。
function sendNotification1(e) {
Logger.log(JSON.stringify(e));
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var row = e.range.getRow();
var col = e.range.getColumn();
var startRow = 2;
var startCol = 3; //Column C
var endCol = 8; //Column H
if(sheet.getName() == "Workable"
&& col >= startCol
&& col <= endCol
&& row >= startRow
&& sheet.getRange(row,9).getValue() > 2 //flag_count column > 2
&& sheet.getRange(row,11).getValue() == "" //action column null
)
{
var campground_id = sheet.getRange(row,2).getValue();
var email = 'your@email.com';
var subject = "New Listing Flagged for Fraud";
var body = 'Campground ' + campground_id + ' has been flagged for fraud. Please resolve ASAP in the QA Google Sheet. Thank you!';
MailApp.sendEmail(email, subject, body);
}
}
Workable
.Workable
。 Check the value in column I if greater than 2. Lastly, check if column K is null/empty Checkbox column included that will act as a checker button to trigger the email notification.包含的复选框列将用作检查器按钮以触发电子邮件通知。
Sample Code:示例代码:
function sendNotification(e) {
Logger.log(JSON.stringify(e));
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var row = e.range.getRow();
var col = e.range.getColumn();
var startRow = 2;
if(sheet.getName() == "Workable"
&& col == 9
&& row >= startRow
&& sheet.getRange(row,9).isChecked()
&& sheet.getRange(row,10).getValue() > 2 //flag_count column > 2
&& sheet.getRange(row,12).getValue() == "" //action column null
)
{
var campground_id = sheet.getRange(row,2).getValue();
var email = 'your@email.com';
var subject = "New Listing Flagged for Fraud";
var body = 'Campground ' + campground_id + ' has been flagged for fraud. Please resolve ASAP in the QA Google Sheet. Thank you!';
MailApp.sendEmail(email, subject, body);
}
}
Sample Sheet:样品表:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.