我对GAS相对较新,但过去曾在其他类似项目中取得过成功。我正在尝试向我的静态地址(我的)发送一封电子邮件,当我在“表格中的甘特图”中的G行下拉列表中选择“过期”时。我已经从各种来源将以下代码放在一起,并有一个sendEmail>来自电子表格>在编辑触发器设置。
function sendEmail(e) {
if (e.value == 'Past Due' && e.range.getColumn() == 7) {
var row = e.range.getRow();
var sSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Gantt Chart");
var emailAddress = "example@email.com";
var subject = "Your Task is Past Due"
var message = "You have a task that is past due. Please refer to the Yearly Work Plan for more information. DO NOT RESPOND TO THIS MESSAGE.";
MailApp.sendEmail(emailAddress, subject, message);
}
}
当我从下拉列表中选择“过期”时,没有任何反应。我没有收到电子邮件,也没有收到失败通知。我觉得这可能是我的触发器的一个问题,但似乎无法解决如何解决它(即使花了几个小时在论坛,博客和视频上挖掘)。
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
我使用这个小函数来测试在数据验证列中进行更改时会触发onEdit。
function sendSomething(e) {
var ts=Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MM:dd:yyyy HH:mm:ss");
var desc='This is an onEdit Trigger';
e.source.getSheetByName('Logger').appendRow([ts,desc]);
if(e.source.getActiveSheet().getName()=='RowAndCols' && e.range.getColumn()==2){
e.source.getSheetByName('Logger').appendRow([ts,'this is the edit from RowAndCols','Current Value is ' + e.value,'Row = ' + e.range.getRow()]);
}
}
在我的情况下,我使用了命名范围,是否无替代方案并验证了ColumnB。
这是我的记录器表上的输出。
12:15:2017 11:22:49 this is the edit from RowAndCols Current Value is Yes
12:15:2017 11:22:51 This is an onEdit Trigger
12:15:2017 11:22:51 this is the edit from RowAndCols Current Value is No
12:15:2017 11:22:53 This is an onEdit Trigger
12:15:2017 11:22:53 this is the edit from RowAndCols Current Value is Yes
12:15:2017 11:22:56 This is an onEdit Trigger
12:15:2017 11:22:56 this is the edit from RowAndCols Current Value is No
12:15:2017 11:22:58 This is an onEdit Trigger
12:15:2017 11:22:58 this is the edit from RowAndCols Current Value is Yes
12:15:2017 11:23:59 This is an onEdit Trigger
12:15:2017 11:23:59 this is the edit from RowAndCols Current Value is Yes Row = 5
12:15:2017 11:24:00 This is an onEdit Trigger
12:15:2017 11:24:00 this is the edit from RowAndCols Current Value is No Row = 6
12:15:2017 11:24:02 This is an onEdit Trigger
12:15:2017 11:24:02 this is the edit from RowAndCols Current Value is Yes Row = 7
12:15:2017 11:24:04 This is an onEdit Trigger
12:15:2017 11:24:04 this is the edit from RowAndCols Current Value is No Row = 8
我的工作表名称是RowAndCols,我的Logger工作表名称是Logger。
似乎工作正常。