【问题标题】:Is there a way to send an automated email from two consecutive identical Google form entries in Google sheets?有没有办法从 Google 表格中的两个连续相同的 Google 表单条目发送自动电子邮件?
【发布时间】:2022-01-11 22:05:40
【问题描述】:

这里是学校管理员。

我们在语言学院使用 Google 表单进行出勤登记。

google 表单使用复选框网格,学生姓名为行,以下选项为列:

  • 现在
  • 缺席
  • 迟到
  • 在线
  • 缺少作业

这些回复被发送到由管理员手动检查的电子表格。

我们目前有一个系统,如果学生连续两节或更长时间缺课,教师应该口头通知管理人员,但许多人不在中心工作,可能忘记更新管理员。

我一直在寻找一个脚本,如果学生连续两次出现“缺席”条目,该脚本将触发向指定电子邮件地址发送电子邮件,但在学生再次参加时也会重置。

或者,可以将连续缺席 2 次的学生姓名(第 1 行中的信息)添加到替代电子表格中进行编译。

希望有人可以提供帮助!谢谢!

In this example Sofia Vergara (I wish!) was absent three times in a row so an email should be triggered after the second absence. Then reset after she attends the fourth class (E5). Juan Lopez then is absent for two classes in a row and should be added to the absentee list

【问题讨论】:

  • 我认为如果每天一次就足够了,可以使用 formSubmit 触发器来获得最快的反应或任何基于时间的触发器。

标签: google-apps-script google-sheets automation google-forms


【解决方案1】:

启动一次 myTriggerSetup

const adresseEmail = 'xxxxxxxxxxx@gmail.com'

function myTriggerSetup() {
  if(!isTrigger('onFormSubmit')) {
    ScriptApp.newTrigger('onFormSubmit')
      .forSpreadsheet(SpreadsheetApp.getActive())
      .onFormSubmit()
      .create();
  }
}
function isTrigger(funcName) {
     var r=false;
     if(funcName) {
       var allTriggers=ScriptApp.getProjectTriggers();
       var allHandlers=[];
       for(var i=0;i<allTriggers.length;i++) {
         allHandlers.push(allTriggers[i].getHandlerFunction());
       }
       if(allHandlers.indexOf(funcName)>-1) {
         r=true;
       }
     }
     return r;
}

function onFormSubmit(e) {
  var sheet = SpreadsheetApp.getActiveSheet();
  var row = sheet.getActiveRange().getRow();
  var column = e.values.length + 1;
  for (var i=2;i<=column;i++){
    if (sheet.getRange(row,i).getValue()=='Absent' && sheet.getRange(row-1,i).getValue()=='Absent'){
      MailApp.sendEmail({
        to: adresseEmail,
        subject: 'Consecutive absences ' + sheet.getName(),
        htmlBody: sheet.getRange(1,i).getValue(), 
      });
    }
  }
}

【讨论】:

  • 这太棒了,谢谢!!!我已经摆弄代码一个小时了,但是有没有办法将工作表的名称添加到主题中?例如。 ““工作表名称”连续缺席?这将为我们的管理人员节省大量时间!再次感谢 Mike!
  • 是的,意思是subject: 'Consecutive absences ' + sheet.getName(),我已经更新了我的答案。
  • 非常感谢迈克!
  • 请检查答案,以便为其他请求者突出显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-14
  • 1970-01-01
  • 1970-01-01
  • 2014-09-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多