问题描述
我是脚本新手,不要经常这样做,所以请原谅我这很可怕。我设置了一个脚本,该脚本会自动输入4个日期。某些单元格被编辑后,当前日期为30天,60天和90天。那部分工作正常。但是我的电子邮件脚本不起作用。我希望检查3栏是否有任何通知日,并相应地发送电子邮件,例如,如果在第9栏中发送了30天通知,或者在11栏中发送了60天通知。我让电子邮件脚本发送了电子邮件,但现在还没有,还没有进入多列检查部分。
function onEdit() {
var now = new Date(); // Fri Jul 05 09:53:12 GMT+05:30 2019
var nowInMS = now.getTime(); // 1562300592245
var add = 24 * 60 * 60 * 1000; // 43200000 = 24 hours in
milliseconds
var dateT = nowInMS + (add*30); // 1562343792245
var dateS = nowInMS + (add*60); // 1562343792245
var dateN = nowInMS + (add*90); // 1562343792245
var futureDateT= new Date(dateT); // Fri Jul 05 21:53:12 GMT+05:30 2019
var futureDateS= new Date(dateS); // Fri Jul 05 21:53:12 GMT+05:30 2019
var futureDateN= new Date(dateN); // Fri Jul 05 21:53:12 GMT+05:30 2019
var futureDateFormattedT = Utilities.formatDate(futureDateT,Session.getScriptTimeZone(),"dd-MMM-yy hh:mm a");
var futureDateFormattedS = Utilities.formatDate(futureDateS,"dd-MMM-yy hh:mm a");
var futureDateFormattedN = Utilities.formatDate(futureDateN,"dd-MMM-yy hh:mm a");
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "Sheet2" ) { //checks that we're on Sheet1 or not
var r = s.getActiveCell();
if( r.getColumn() == 7 ) { //checks that the cell being edited
var nextCell = r.offset(0,1);
if( nextCell.getValue() === '' ) //checks if the adjacent cell is empty or not?
nextCell.setValue(new Date());
var tCell = r.offset(0,2);
//var now = new Date();
//var MS = today.getDate();
tCell.setValue(new Date(futureDateFormattedT));
//var sdate = MS + (dayInMs*60)
var sCell = r.offset(0,4);
sCell.setValue(new Date(futureDateFormattedS));
//var ndate = MS + (dayInMs*90)
var nCell = r.offset(0,6);
nCell.setValue(new Date(futureDateFormattedN));
}
}
}
function sendEmails3() {
var EMAIL_SENT = "EMAIL_SENT";
var today = new Date().toLocaleDateString(); // Today's date,without time
var ss = SpreadsheetApp.getActive()
var sheet = ss.getSheetByName("sheet2")
sheet.activate()
var startRow = 2; // First row of data to process
var numRows = 999; // Number of rows to process
// Fetch the range of cells A2:B999
var dataRange = sheet.getRange(startRow,2,numRows,999)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var emailAddress = "[email protected]";
var subject = "PPAP Reminder";
var message = "Part Number " + row[0] + " " + "Rev" + " " + row[1] + " " + row[2] + '\n'
+ "Note the (T,E Disposition) is 30 days past entry" + '\n' + '\n' + '\n'
+ "A: Approved (authorized for production shipments)" + '\n'
+ "R: Rejected (not authorized for production shipments)" + '\n'
+ "E: Interim Approval – Engineering Change in Process" + '\n'
+ "T: Interim Approval – Temporary Action in Place (Action plan in place utilizing containment,repair,or non-standard process to insure components meet requirements.)"; // Third column
var emailSent = row[10];
var reminderDate = row[9].toLocaleDateString(); // date specified in cell I
if (reminderDate != today) // Skip this reminder if not for today
continue;
if (emailSent != EMAIL_SENT) { // Prevents sending duplicates
var emailSent = row[10];
MailApp.sendEmail(emailAddress,subject,message)
sheet.getRange(startRow + i,10).setValue(EMAIL_SENT);
// Make sure the cell is updated right away in case the script is interrupted
SpreadsheetApp.flush();
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)