我是脚本新手。我有一个函数来检查当前时间和之前电子表格中记录的时间之间的差异。如果差异超过4小时,则需要向相关人员发送邮件。
当我尝试执行此代码时,它只会成功运行第一个if条件并在那里结束。根本没有执行第二个嵌套的if语句。代码中所需的所有帮助和必要的更改都将受到高度赞赏。
function warningemail() {
var check_sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Request Form Responses");
var findColJ = check_sheet.getRange('J:J').getValues();
var findColL = check_sheet.getRange('L:L').getValues();
var findColE = check_sheet.getRange('E:E').getValues();
var findColI = check_sheet.getRange('I:I').getValues();
for (var y = 0, lengths = findColJ.length; y < lengths; y++) {
if (findColJ[y][0] == "In Progress") {
var dt1 = new Date();
var time1 = new Date(dt1.getTime());
var prTime = Utilities.formatDate(time1, "GMT+0530", "MM/dd/yyyy HH:mm:ss");
var dt2 = new Date(findColL[y][0]);
var time2 = new Date(dt2.getTime());
var etaTime = Utilities.formatDate(time2, "GMT+0530", "MM/dd/yyyy HH:mm:ss");
Logger.log(prTime); //05/13/2017 12:44:09
Logger.log(etaTime); //05/13/2017 02:26:00
if (prTime-etaTime > 3600000*4) { // Need to check the diff between current time and prTime
var subject = "Peer Review Request Unattended| PCID: " + findColE[y][0];
var body = "";
var htmlmail = "<p>Hi,</p>";
htmlmail += "<p>*******************This is a system generated email. Do not reply to this mail.*******************</p>";
GmailApp.sendEmail(findColI, subject,body,{ htmlBody:htmlmail });
}
}
}
}