以编程方式创建触发器时重载的构造函数错误

时间:2014-08-28 22:17:06

标签: google-apps-script google-form

我想创建一个流程,当人提交表单时,我只会填写信息(不是每个字段都需要填写)。找到代码(http://www.labnol.org/internet/google-docs-email-form/20884/),根据作者做了所有事情,但对我没有用。我不是编码专家,所以我需要你的帮助。

以下是代码:

function Initialize() {

  var triggers = ScriptApp.getScriptTriggers();

  for(var i in triggers) {
    ScriptApp.deleteTrigger(triggers[i]);
  }

  ScriptApp.newTrigger("SendGoogleForm")
  .forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
  .onFormSubmit()
  .create();

}

function SendGoogleForm(e) 
{  
  try 
  {      
    // You may replace this with another email address
    var email = "justbeincredible@gmail.com";

    // Optional but change the following variable
    // to have a custom subject for Google Form email notifications
    var subject = "New Driver Application Arrived";  

    var s = SpreadsheetApp.getActiveSheet();
    var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];    
    var message = "";    

    // Only include form fields that are not blank
    for ( var keys in columns ) {
      var key = columns[keys];
      if ( e.namedValues[key] && (e.namedValues[key] != "") ) {
        message += key + ' :: '+ e.namedValues[key] + "\n\n"; 
      }
    }

    // This is the MailApp service of Google Apps Script
    // that sends the email. You can also use GmailApp for HTML Mail.

    MailApp.sendEmail(email, subject, message); 

  } catch (e) {
    Logger.log(e.toString());
  }

}

以下是我运行Initialize进行测试时得到的结果:

Cannot call overloaded constructor forSpreadsheet with parameters
(null) because there is more than one matching constructor signature:
interface SpreadsheetTriggerBuilder forSpreadsheet(Spreadsheet)
interface SpreadsheetTriggerBuilder forSpreadsheet(String) (line 12,
file "Code")

2 个答案:

答案 0 :(得分:1)

在收集回复的Google电子表格的脚本编辑器中添加代码,而不是在表单编辑器中。 [source]

说明:错误消息表明forSpreadsheet()的参数为(null)。你喂它SpreadsheetApp.getActiveSpreadsheet(),所以评估为null。该方法仅适用于Spreadsheet绑定脚本。

答案 1 :(得分:0)

该插件在勇敢的浏览器上不起作用。如果您当前不使用它,请尝试在Google Chrome上运行。