【问题标题】:Sending email reminders for Google Sheet tasks为 Google 表格任务发送电子邮件提醒
【发布时间】:2021-12-14 05:33:58
【问题描述】:

根据以下建议更新了代码,电子邮件不包含摘要,任何解决此问题的帮助将不胜感激!下面附上测试文件,

function sendEmail(){
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName("2021-12 {3600950}").activate();
    var ss = 
    SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();  
    //data on sheet, filter for any row where the status is still "assigned"
     var data = ss.getDataRange().getValues()
        var assigned = data.reduce(function(acc, curr) {
     if(curr[5] === "assigned") {
         acc.push(curr)
       }
      return acc
      },[])

   // unique list of emails
    var Assignee = [0]
    var Summary = [2]

     var compareAssignee = []
     for (i=0; i<assigned.length; i++){
     compareAssignee.push(assigned[i][0])
     }
    //loop unique emails, all the tasks for each of those users, and send a simple email with the tasks

      for (var i=0; i<Assignee.length; i++){
      var Summary = assigned.reduce(function(acc, curr) {
       if(curr[0] === Assignee[i])
       {
    acc.push(String.fromCharCode() + "pending task: " + curr[2] + 
  Summary[2]) 

    //this puts a line break before each task, so when the email is 
 sent each one is on its own line.
        }
       return acc
     },[])

   console.log(Summary)
   MailApp.sendEmail
   MailApp.sendEmail(compareAssignee[0],"pending RPP task(s)",Summary[2])
     }
 }

  function scheduleEmails(){
  // Schedules for the first of every month
  ScriptApp.newTrigger("sendEmail")
  .timeBased()
  .onMonthDay(28)
  .atHour(1)
  .create();
    }

【问题讨论】:

  • 我必须为我糟糕的英语水平道歉。不幸的是,我无法理解您来自List item Pulling email address from column 1, task name from column 2, status field “assigned 的问题。我能问你关于你的剧本当前问题的细节和你的目标吗?
  • 我应该更加规范,该表包含以下列 1) 电子邮件 3) 任务名称 6) 状态(已分配的固定状态)。目标是向第 1 列中的电子邮件发送一封电子邮件,以根据第 6 列处于分配状态的状态提醒他们第 3 列中的待处理任务。这将需要在每个月的 30 日运行。
  • 感谢您的回复。现在我注意到已经发布了答案并且已经进行了讨论。在这种情况下,我想尊重现有的答案和讨论。
  • 任何帮助解决问题的人都将不胜感激!我仍然坚持下面提到的两个地方
  • @KaviaVenkatesh 如果您发现问题未包含所有必需的详细信息,例如评论者所要求的,请编辑问题以添加这些详细信息,但如果您有来自答案,请将它们作为新问题发布。

标签: google-apps-script google-sheets


【解决方案1】:

您想在每个月末向任务仍处于“已分配”状态的用户发送一封电子邮件。

下面的 sendEmail 脚本查找每个用户的所有任务,并向他们发送一封电子邮件,列出他们仍然“分配”的每个任务。 编辑:您在上面的评论中指出电子邮件位于 Col 1,任务位于 Col 3,状态位于 Col6。我更新了代码以反映以下内容。

查看此sample email 以查看结果。

第二个函数创建一个每月运行sendEmail 的触发器。您表示您想在当月的最后一天发送电子邮件,但 Google 似乎很难做到这一点。其他一些人想出了解决方法。我喜欢这个:在每月 1 日发送提醒,但在凌晨 1 点!你可以看到更多他们的作品here

function sendEmail(){
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("status").activate();
  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  //grab all the data in the sheet, and then filter for any row where the status is still "assigned"
  var data = ss.getDataRange().getValues()
  var assigned = data.reduce(function(acc, curr) {
    if(curr[5] === "assigned") {
      acc.push(curr)
    }
    return acc
  },[])

  // From all the tasks still in "assigned" status, get a unique list of emails.
  var uniqueEmails = []
  var compareEmails = []
  for (i=0; i<assigned.length; i++){
    compareEmails.push(assigned[i][0])
  }
  uniqueEmails = [...new Set(compareEmails)]

  //loop through the unique emails, grab all the tasks for each of those users, and send a simple email with the tasks listed. 
  for (var i=0; i<uniqueEmails.length; i++){
    var tasksPerUser = assigned.reduce(function(acc, curr) {
      if(curr[0] === uniqueEmails[i]) {
        acc.push(String.fromCharCode(10) + "pending task: " + curr[2]) //this puts a line break before each task, so when the email is sent each one is on its own line.
      }
      return acc
    },[])

  console.log(tasksPerUser)
  MailApp.sendEmail(uniqueEmails[i],"pending tasks",tasksPerUser)
  }
}

function scheduleEmails(){
// Schedules for the first of every month
ScriptApp.newTrigger("sendEmail")
  .timeBased()
  .onMonthDay(1)
  .atHour(1)
  .create();
}

【讨论】:

  • 谢谢,这是一个错误(尝试执行 sendEmail,但无法保存)我不确定语法错误:语法错误。行:20 文件:电子邮件
  • 你能分享你的文件吗?这是我根据您的描述制作的test file
  • 您需要打开对文件的访问权限。
  • 查看您的文件我发现 2 个问题:1) 电子邮件列不包含电子邮件,2) 状态列使用“已分配”而不是“已分配”。第二个问题将阻止找到任何行,因为匹配区分大小写。因此,要么在工作表中使用“已分配”,要么更新脚本中的 if(curr[5] === "assigned") {,使其使用带有初始上限的“已分配”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-09
  • 2022-11-16
  • 2014-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多