javascript - 我怎样才能绕过任何日期或数字?
问题描述
我需要使用谷歌脚本自动发送电子邮件。如果我没有产品条形码或订单确认信息,或者两者都没有,我需要发送电子邮件。这个脚本在我的测试电子表格中工作:
function sendEmails() {
var app = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders").activate();
var lastRow = app.getLastRow();
//Get Stored Email Subject
var getBarcodeSubject = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(2, 2).getValue();
var getConfSubject = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(3, 2).getValue();
//Get Stored Email Template
var getBarcodeEmail = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(2, 1).getValue();
var getConfEmail = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Template").getRange(3, 1).getValue();
//Get Daily Email Quota
var emailQuota = MailApp.getRemainingDailyQuota();
//Get the number of rows in google sheet and take one off for headings row
var totalEmails = lastRow - 1;
//Check there is enough emails in quota
if(totalEmails > emailQuota){
Browser.msgBox("You have " + emailQuota + " emails left today and you're trying to send " + totalEmails + ". The emails were not sent.");
}else{
for(var i = 2; i<=lastRow; i++){
//loop through each row in spreadsheet and get corresponding email and name
var currentEmail = app.getRange(i, 20).getValue();
//check if there is an email available
if(currentEmail.match('@') === null){
continue;
}
var currentName = app.getRange(i, 1).getValue();
var barcode = app.getRange(i, 15).getValues();
var orderCon = app.getRange(i, 11).getValues();
//replace placeholder with the relative stored name
var getBarcodeBody = getBarcodeEmail.replace("{Name}", currentName);
var getConfBody = getConfEmail.replace("{Name}", currentName);
//Check if barcodes are not currently there
if(barcode.match("n")||barcode.match("N")){
//MailApp.sendEmail(currentEmail, getBarcodeSubject, getBarcodeBody);
Logger.log(getBarcodeBody);
}else if(orderCon.match("n")||orderCon.match("N")){
//MailApp.sendEmail(currentEmail, getConfSubject, getConfBody);
Logger.log(getConfBody);
}//close else if
}//close for loop
}Browser.msgBox("Emails have been sent!");//close else statement
}//close function
但是,将在现实世界环境中使用的电子表格在保存条形码和订单确认的列中包含日期。这会引发错误,因为它似乎.match()
不喜欢数字或日期。我尝试了以下方法来解决这个问题,但它也不起作用:
if(barcode !== 'n' || barcode !== 'N'){
continue;
}else if(orderCon !== 'n' || orderCon !== 'N'){
continue;
}else if(barcode == 'n' || barcode == 'N'){
Logger.log(getBarcodeBody);
//MailApp.sendEmail(currentEmail, getBarcodeSubject, getBarcodeBody);
}else if(orderCon == 'n' || orderCon == 'N'){
Logger.log(getConfBody);
//MailApp.sendEmail(currentEmail, getConfSubject, getConfBody);
}else{
Browser.msgBox("There was an error!");
}
我该如何克服呢?谢谢!
更新:似乎if
我尝试的最后一个语句是忽略所有内容。
解决方案
推荐阅读
- html - 显示 flex 高度是 100%,没有滚动条,但不是 100%,有滚动条
- r - 在ggplot中按周汇总出勤率
- pandas - 仅从 pandas 的 datetime.datetime 列中提取日期
- systemd - Salt 使用自定义服务文件启用 systemctl 服务
- python-3.x - 从字符串输入制作摘要数据框
- python-3.x - TypeError:必须是实数,而不是 InstrumentedAttribute
- angular - 在Angular中注销后使JWT令牌无效
- reactjs - 如何在按钮单击时显示子详细信息
- windows - DHCP 工具比 PowerShell 快得多
- java - 使用 Intellij 和 Inno Setup 构建本机 JavaFX 应用程序时,我应该将自定义 .iss 文件放在哪里?