Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 从重复的speadsheet运行Google脚本_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 从重复的speadsheet运行Google脚本

Google apps script 从重复的speadsheet运行Google脚本,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我已经创建了一个谷歌电子表格,其中包括一些基本脚本,当分配给某人的任务到期时,它会给某人发电子邮件。脚本在原始工作表上工作,但当我复制工作表时,除了日期之外什么都不更改,脚本就不再工作了 我没有收到任何错误,只是没有发送电子邮件 我对谷歌脚本还很陌生,没能找到一个好的答案。有人知道问题是什么吗 非常感谢 function myFunction() { var date = new Date(); date.setHours(0); date.setMinutes(

我已经创建了一个谷歌电子表格,其中包括一些基本脚本,当分配给某人的任务到期时,它会给某人发电子邮件。脚本在原始工作表上工作,但当我复制工作表时,除了日期之外什么都不更改,脚本就不再工作了

我没有收到任何错误,只是没有发送电子邮件

我对谷歌脚本还很陌生,没能找到一个好的答案。有人知道问题是什么吗

非常感谢

    function myFunction() {
    var date = new Date();
    date.setHours(0);
    date.setMinutes(0);
    date.setSeconds(0);
    var FormattedTodayDate = Utilities.formatDate(date,'GMT-0600','MM/dd/yyyy')

    //Here we get all the spreadsheets from the spreadsheet app
    var spreadSheets = SpreadsheetApp.getActiveSpreadsheet();
    //Here we pick out the first spreadsheet. 0 is the first tab of the spreadsheet "Active Sheet"
    var currentSheet = spreadSheets.getSheets()[0];


   //Here we set up where on the sheet we want to get the data
   var startRow = 3;
   var numRows = currentSheet.getLastRow()-1;
   var numCols = currentSheet.getLastColumn();

   //We use those numbers to find a range throughout the table (A2 - H* etc) where we want to grab the data from
   var dataRange = currentSheet.getRange(startRow, 1, numRows, numCols);

   //Using the data range, grab all the values
   var data = dataRange.getValues();

  for(i in data){
  var row = data[i];
  var reminderDate = new Date(row[1]);
  var dueDate = new Date(row[3]);
  var FormattedReminderDate = Utilities.formatDate(reminderDate,'GMT-0600', 'MM/dd/yyyy')
  var FormattedDueDate = Utilities.formatDate(dueDate,'GMT-0600', 'MM/dd/yyyy')
  if(row[0] === ''){

  //      Logger.log(FormattedTodayDate);
  //      
  //      Logger.log(FormattedReminderDate);
  //      
  //      Logger.log(FormattedReminderDate == FormattedTodayDate);

  if(FormattedReminderDate == FormattedTodayDate){
      MailApp.sendEmail({
        to: row[7],
        subject: row[4] + " task due on " + FormattedDueDate,
        htmlBody: "The following " + row[4] + " task is coming due on <b>" + FormattedDueDate + "</b> : <br/> <br>" + row[5] + "<br> </br>Go to Google Spreadsheet for more details: https://docs.google.com/spreadsheets/d/1jIBX5By1jhro1V-gHXPPlhIOXDLut6CMvaq92uW5bFw/edit#gid=0&range=" + row[8] + "<br/><br> Please remember to add the word 'done' to the 'done?' column when you complete this task.",
      })
  }
  if(FormattedDueDate == FormattedTodayDate){
      MailApp.sendEmail({
        to: row[7],
        subject: row[4] + " task due TODAY",
        htmlBody: "The following " + row[4] + " task has not been completed and is due TODAY: <br/> <br>" + row[5] + "<br> </br>Go to Google Spreadsheet for more details: https://docs.google.com/spreadsheets/d/1jIBX5By1jhro1V-gHXPPlhIOXDLut6CMvaq92uW5bFw/edit#gid=0&range=" + row[8] + "<br/><br> Please remember to add the word 'done' to the 'done?' column when you complete this task.",
      })
  }

} 
}
}
函数myFunction(){
变量日期=新日期();
日期.设定时间(0);;
日期。设置分钟数(0);
日期。设置秒(0);
var FormattedTodayDate=实用程序.formattDate(日期'GMT-0600','MM/dd/yyyy')
//这里我们从电子表格应用程序获得所有电子表格
var spreadSheets=SpreadsheetApp.getActiveSpreadsheet();
//在这里,我们选择第一个电子表格。0是电子表格“活动工作表”的第一个选项卡
var currentSheet=spreadSheets.getSheets()[0];
//在这里,我们在工作表上设置了获取数据的位置
var startRow=3;
var numRows=currentSheet.getLastRow()-1;
var numCols=currentSheet.getLastColumn();
//我们使用这些数字在整个表(A2-H*等)中找到一个范围,从中获取数据
var dataRange=currentSheet.getRange(startRow,1,numRows,numCols);
//使用数据范围,获取所有值
var data=dataRange.getValues();
对于(数据中的i){
var行=数据[i];
var提醒日期=新日期(第[1]行);
var dueDate=新日期(第[3]行);
var formattedemenderDate=Utilities.formattdate(emenderDate,'GMT-0600','MM/dd/yyyy')
var FormattedDueDate=Utilities.formattate(dueDate,'GMT-0600','MM/dd/yyyy')
如果(第[0]行=“”){
//Logger.log(格式为TodayDate);
//      
//Logger.log(格式化提醒日期);
//      
//Logger.log(FormattedEmlerateDate==FormattedTodayDate);
如果(FormattedEmlerateDate==FormattedTodayDate){
MailApp.sendmail({
收件人:第[7]行,
主题:行[4]+“任务到期日”+格式化的截止日期,
htmlBody:“以下“+行[4]+”任务将于“+格式化的DueDate+”到期:

“+行[5]+”

转到谷歌电子表格了解更多详细信息:https://docs.google.com/spreadsheets/d/1jIBX5By1jhro1V-gHXPPlhIOXDLut6CMvaq92uW5bFw/edit#gid=0&range=“+第[8]行+“

完成此任务时,请记住在“完成”列中添加“完成”一词。”, }) } 如果(FormattedDueDate==FormattedTodayDate){ MailApp.sendmail({ 收件人:第[7]行, 主题:行[4]+“任务今天到期”, htmlBody:“以下“+行[4]+”任务尚未完成,今天到期:

“+行[5]+”

转到谷歌电子表格了解更多详细信息:https://docs.google.com/spreadsheets/d/1jIBX5By1jhro1V-gHXPPlhIOXDLut6CMvaq92uW5bFw/edit#gid=0&range=“+第[8]行+”

完成此任务时,请记住在“完成”列中添加“完成”一词。“, }) } } } }
谢谢大家。原来这个问题是由我们的垃圾邮件过滤器阻止通知引起的。

谢谢大家。原来这个问题是由我们的垃圾邮件过滤器阻止通知引起的。

似乎没有任何明显的原因它不应该工作。你能编辑这个问题来解释你是如何运行这个功能的吗,h您如何知道它不起作用,以及有哪些错误(如果有)你收到了吗?谢谢@Cameron Roberts我已经更新了问题try View/executionsHanks@Cooper View/Executions显示“已完成”且没有错误。我已经为今天创建了一个“测试”任务,该任务触发了一封电子邮件,但不幸的是没有发送任何消息。听起来好像是时候使用调试器逐步完成脚本并找出错误了没有什么问题。似乎没有任何明显的原因说明它不应该工作。您可以编辑问题来解释您是如何运行该函数的,您如何知道它不工作的,以及哪些错误(如果有)你收到了吗?谢谢@Cameron Roberts我已经更新了问题try View/executionsHanks@Cooper View/Executions显示“已完成”且没有错误。我已经为今天创建了一个“测试”任务,该任务触发了一封电子邮件,但不幸的是没有发送任何消息。听起来好像是时候使用调试器逐步完成脚本并找出错误了我不知道怎么了。