需要JS帮助 - 观看谷歌表格专栏,通过Gmail发送电子邮件以获取更新的值



当 E 列在工作表的特定选项卡上更新值为"TRUE"时,我需要向 3 个人发送电子邮件。我发现了很多关于如何引用电子表格的信息,但没有关于如何将其定向到特定选项卡的信息......此工作表有两个选项卡。

任何建议将不胜感激!我试过这个:(管道是选项卡名称。

function sendEmails() {

var sSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("PIPELINE");
var sheetNameToWatch = "PIPELINE";
var columnNumberToWatch = 5; // column A = 1, B = 2, etc.
var valueToWatch1 = "TRUE";

if(column[5] = 'TRUE')

//Define Notification Details
var recipients = "kessla.sloan@skysmb.com, email@email.com";
var subject = "TEST Update"+e.range.getSheet().getName();
var body = "google sheet update - TEST";
//Send the Email
GmailApp.sendEmail(recipients, subject, body);
}

由于您希望每次对工作表进行编辑时都运行脚本,因此应使用onEdit(e)触发器。

function onEdit(e){
sendEmails(e.range);
}

此触发器的参数e包含编辑范围,因此您可以轻松检查 if 中的列和工作表。

function sendEmails(range) {
var sheetNameToWatch = "PIPELINE";
var columnNumberToWatch = 5; // column A = 1, B = 2, etc.
var valueToWatch1 = "TRUE";
//here you check if all the requirements are met
var rightSheet = range.getSheet().getName() == sheetNameToWatch;
//the == are used for comparaison, while = are used only for assignment.
var rightColumn = range.getColumn() == columnNumberToWatch;
var rightValue = range.getValue() == valueToWatch1;
// the && are "and" operators, so that the script run only of the 3 conditions are met.
if(rightSheet && rightColumn && rightvalue){ //don't forget the brackets here
//Define Notification Details
var recipients = "kessla.sloan@skysmb.com, email@email.com";
var subject = "TEST Update"+ range.getSheet().getName();
var body = "google sheet update - TEST";
//Send the Email
GmailApp.sendEmail(recipients, subject, body);
}
}

最新更新