簡體   English   中英

使用 appscript 為谷歌工作表任務發送電子郵件提醒

[英]Sending email reminders for google sheet tasks with appscript

根據以下建議更新了代碼,電子郵件不包含摘要,任何幫助解決此問題將不勝感激! 測試文件附在下面,函數 sendEmail(){ SpreadsheetApp.getActiveSpreadsheet().getSheetByName("2021-12 {3600950}").activate(); var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
//工作表上的數據,過濾狀態仍為“已分配”的任何行 var data = ss.getDataRange().getValues() varassigned = data.reduce(function(acc, curr) { if(curr[5] === "已分配") { 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();
    }

您希望在每個月末向任務仍處於“已分配”狀態的用戶發送一封電子郵件。

下面的 sendEmail 腳本查找每個用戶的所有任務,並向他們發送一封電子郵件,列出他們仍然“分配”的每個任務。 編輯:您在上面的評論中指出電子郵件在第 1 列,任務在第 3 列,狀態在第 6 列。 我更新了代碼以反映下面的內容。

查看此示例電子郵件以查看結果。

第二個函數創建一個觸發器,每個月運行sendEmail 您表示您想在該月的最后一天發送電子郵件,但 Google 似乎很難做到這一點。 其他一些人提出了解決方法。 我喜歡這個:在每月 1 號發送提醒,但在凌晨 1 點! 你可以在這里看到更多他們的作品

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();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM