情况:
我有以下脚本,给我发送了一封带有关闭票证的电子邮件。


问题:


该脚本向我发送任何截止日期的所有已关闭票证。我需要您仅将当天的封闭票发送给我。


关闭日期列的格式为“ 29/11/2016 12:34:00”。



  function emailv2() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var Support = ss.getSheetByName("Historic");
  var lastrow = Support.getLastRow();

  var data1 = Support.getRange(3, 1, lastrow).getValues(); // Ticket# Column
  var data2 = Support.getRange(3, 2, lastrow).getValues(); // Comment Column
  var data3 = Support.getRange(3, 3, lastrow).getValues(); // Status Column
  var data4 = Support.getRange(3, 9, lastrow).getValues(); // Close Date Column

  var date = Utilities.formatDate(new Date(), "GMT-3", "dd/MM/yyyy HH:mm"); // Funtion Date + Format

  var report = " "
  var supportTable ="";
  for(var i in data3){
    if(data3[i]=='Closed') supportTable += "<tr><td style='color:blue;padding:5px'>" + "<a href=http://otrserver/otrs/index.pl?Action=AgentTicketZoom;TicketNumber="+data1[i]+">"+data1[i]+"</a>"
                                      + "</td><td style='padding:5px'>" + data2[i]
                                      + "</td><td style='padding:5px'>" + data3[i]
                                      + "</td></tr>";
  }

  report ="Estimados: <br><br> Les envio el shift <br><br><table style='border-collapse:collapse;'border = 1 cellpadding = 5; align='center'><tr><th style='background-color:black;color:white'>Ticket#</th><th style='background-color:black;color:white'>Comment</th><th style='background-color:black;color:white'>Status</tr>" + supportTable + "</table>";

  MailApp.sendEmail("[email protected]",
                    "Shift Change -" + date,
                    report,
                    {name: 'Automatic Emailer Script',
                    htmlBody: report});
}

最佳答案

我添加了一个测试日期的函数,并编辑了if语句以使用它:

function emailv2() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var Support = ss.getSheetByName("Historic");
  var lastrow = Support.getLastRow();

  var data1 = Support.getRange(3, 1, lastrow).getValues(); // Ticket# Column
  var data2 = Support.getRange(3, 2, lastrow).getValues(); // Comment Column
  var data3 = Support.getRange(3, 3, lastrow).getValues(); // Status Column
  var data4 = Support.getRange(3, 9, lastrow).getValues(); // Close Date Column

  var date = new Date()

  var report = " "
  var supportTable ="";
  for(var i in data3){
    if((data3[i]=='Closed') && (testDate(data4[i][0], date))) supportTable += "<tr><td style='color:blue;padding:5px'>" + "<a href=http://drsc.nubicua.net/otrs/index.pl?Action=AgentTicketZoom;TicketNumber="+data1[i]+">"+data1[i]+"</a>"
                                      + "</td><td style='padding:5px'>" + data2[i]
                                      + "</td><td style='padding:5px'>" + data3[i]
                                      + "</td></tr>";

  }

  report ="Estimados: <br><br> Les envio el shift <br><br><table style='border-collapse:collapse;'border = 1 cellpadding = 5; align='center'><tr><th style='background-color:black;color:white'>Ticket#</th><th style='background-color:black;color:white'>Comment</th><th style='background-color:black;color:white'>Status</tr>" + supportTable + "</table>";

  MailApp.sendEmail("[email protected]",
                    "Shift Change -" + date,
                    report,
                    {name: 'Automatic Emailer Script',
                    htmlBody: report});
}

function testDate (dateToTest1,dateToTest2) {
    return (dateToTest1.getFullYear() === dateToTest2.getFullYear()) &&
           (dateToTest1.getMonth() === dateToTest2.getMonth()) &&
           (dateToTest1.getDate() == dateToTest2.getDate());
}


旧的回应

更改您的IF以也比较日期。如果提供的都是日期,请将其格式化为仅日期而不是时间

var date = Utilities.formatDate(new Date(), "GMT-3", "dd/MM/yyyy"); // Function Date + Format


然后将If更改为:

if((data3[i]=='Closed') && (date === data4))


请注意,这是未经测试的,因为我没有您的电子表格的副本,但是应该可以帮助您。

关于javascript - Google脚本-仅当今天等于今天时才从电子表格中提取行数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40873675/

10-12 14:10