google-apps-script - 如果条件无法正常运行
问题描述
我的脚本正在向列中的给定收件人发送消息,即使已经发送了一个。目标是在活动工作表上搜索并检查活动行的两列是否符合if
条件。如果是这样,则执行这些MailApp.sendEmail()
行。
但是,即使该行不符合条件,它也会发送另一封电子邮件。我认为这是由于我如何定位for
-loop 和if
,或者我的代码中缺少某些内容。
目标:如果两列的活动行符合条件 > 发送电子邮件。
其他任何内容 > 忽略/跳过行。
function sendOnEdit(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Dump");
var startRow = 1; // Bypass firts Row that contain Column Titles
var dataRange = sheet.getDataRange();
var data = dataRange.getValues();
for (var rownum = startRow; rownum < data.length; rownum++) { //loop to search for reso == x && emailSent != y
var casenum = data[rownum][5]; // Active Row for Case# Column
Logger.log("Captured Case#: " + casenum);
var emailAddress = data[rownum][1]; // grabs the email address / Email Address Col
Logger.log("Captured Email: " + emailAddress );
var reso = data[rownum][12]; // check cell value / on Spreadsheet reso column is on Data Validation that's either "Yes" or empty.
Logger.log("Captured Y/N: " + reso);
var emailSent =data[rownum][17]; // Current active cell for col "DONE"
Logger.log("Captured DONE?: " + emailSent);
var x = "Yes";
var y = "DONE";
if ( reso == x && emailSent != y ) { // if this is true it should send email with details below if not it will do nothing.
var body = "Hello!";
body += '<p></p>';
//Add to body ...
var subject = "Message Subject" + casenum;
MailApp.sendEmail(emailAddress, subject, body,
{name: 'Automatic Teamline Email', htmlBody: body});
sheet.getRange(rownum + 1, 19).setValue("DONE"); // This will set value of current cell to "DONE"
}
}
}
解决方案
推荐阅读
- python - 使用scrapy获取url列表,然后只发送不在给定列表中的请求
- flutter - 检查 Firebase 用户是否在 Flutter 中首次使用 google 进行身份验证
- swift - dateDecodingStrategy 显示不正确的年份
- python - 难以理解计算变换网格的 Python 代码
- android - 将 Gradle 和 Android Studio 更新到 3.5 后复制 Hamcrest 和 JUnit 类
- html - 如何将链接的图像/gif 添加到更大的图像上?
- angular - Angular 应用程序因 JitCompiler 错误而崩溃
- firebase - Firestore - 如果需要,在删除时替换集合文档
- c++ - 如何将派生类的 std::list 而不是父类的 std::list 传递给函数?
- django - Django覆盖详细视图获取方法