【发布时间】:2016-08-16 13:53:39
【问题描述】:
我尝试根据自己的需要修改脚本,但出现错误“TypeError: Function getDate not found in the object . (line 13, file "Code")”。
事实上,我想将今天的日期与第 [7] 行中包含的日期进行比较,并针对包含 Projects 的电子表格的每一行向某些人发送提醒...
这是我的实际代码:
function sendEmails(step) {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 3; // First row of data to process, Start at second row because the first row contains the data labels
var numRows = sheet.getLastRow(); // Number of rows to process -> all rows which are not empty
var totalRows = numRows - startRow +1; // total rows to process is numRows on which we remove start row +1
// Fetch the range of cells
var dataRange = sheet.getRange(startRow, 1, totalRows, 20) // range of columns to process
// Fetch values for each row in the Range
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[2] + ", " + row [3] + ", " + row [4]; // email addresses for email distribution
var messagePVEnd = "The PV of project " + "'"+ row[0] +"'" + " is ending the " + row[7].getDate() + "/" + (row[7].getMonth+1) + "/" + row[7].getFullYear() + " , please push " + row[1] + " to get the reports."; // Email content for PV End
var messagePVMidStatus = "The PV of project " + "'" + row[0] + "'" + " will be at 500h the " + row[6].getDate() + "/" + (row[6].getMonth()+1) + "/" + row[6].getFullYear() + " , please push " + row[1] + " to get the intermediate status."; // Email content for PV after 500h
var messagePVOut = "The PV of project " + "'"+ row[0] +"'" + " is supposed to be finished since " + row[7].getDate() + "/" + (row[7].getMonth()+1) + "/" + row[7].getFullYear() + " , please push " + row[1] + " to get the reports and confirm that all reports are received in PV follow up google sheet."; // Email content for PV Out
var subjectPVEnd = row [0] + " -- Reminder for PV ending to get report from " + row [1]; // Email subject for PV end
var subjectPVMidStatus = row [0] + " -- Reminder to get PV intermediate status after 500h from " + row [1]; // Email subject for PV after 500h
var subjectPVOut = row [0] + " -- Reminder, PV should be finished with all reports received from " + row [1]; // Email subject for PV Out
if (row[8]==5) { // if date of PV status after 500h is equal to 5 days
MailApp.sendEmail(emailAddress, subjectPVMidStatus, messagePVMidStatus)
}
else if (row[8]==1) { // if date of PV status after 500h is equal to 1 day
MailApp.sendEmail(emailAddress, subjectPVMidStatus, messagePVMidStatus)
}
else if (row[9]==5) { // if PV end date is equal to 5 days
MailApp.sendEmail(emailAddress, subjectPVEnd, messagePVEnd)
}
else if (row[9]==1) { // if PV end date is equal to 1 day
MailApp.sendEmail(emailAddress, subjectPVEnd, messagePVEnd)
}
else if (row[10]!="yes") {
for (var j=1; j<=9; j++) {
if (row[9]==-(j*10)) { // if PV end date is out of date by multiple of 10 days up to 100 days (except if report are received)
MailApp.sendEmail(emailAddress, subjectPVOut, messagePVOut)
}
}
}
}
}
电子邮件已正确发送,但邮件中的日期格式存在问题,我无法弄清楚我做错了什么。 欢迎任何支持!
提前致谢,
编辑 17/08: 这是相应电子表格的图片。 enter image description here
【问题讨论】:
标签: javascript date google-apps-script google-sheets date-formatting