破损的提交表格

时间:2015-07-08 17:45:33

标签: google-apps-script

我有一份我们用于客户的调查表。它是一系列多个选择题和一些文本字段条目。最后,您点击“提交”,系统会发送一封电子邮件,其中包含对质量经理的所有回复。最近,表单停止工作,我发现很多人通过将docslist更改为DriveApp来成功解决问题。但是,现在我收到了错误:

TypeError: Cannot read property "response" from undefined. (line 10, file "")

整个代码如下:

/// Get template from Google Docs and name it
var docTemplate = "1vCv-NR9c2G5q6f6EJ2CL4zAEQe_37OE7MgsSLTIKheY"; // *** replace with your template ID ***
var docName = "ClientSurvey";

// When Form Gets submitted
function onFormSubmit(e) {
//Get information from form and set as variables
Logger.log(Utilities.jsonStringify(e));

var formResponses = e.response.getItemResponses();

  Logger.log(formResponses[0].toString());

  var service_type = formResponses[0].getResponse().toString();

var email_address = "notrealaddress@ntainc.com, notrealaddress@ntainc.com"
//var service_type = e.values[0];
 var d = new Date();
  var timeStamp = d.getTime();  

// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DriveApp.getFileById(docTemplate)
.makeCopy(docName+timeStamp)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
var copyBody = copyDoc.getActiveSection();



// Replace place holder keys,in our google doc template
copyBody.replaceText('keyServiceType', service_type);


 for (var i = 0; i < formResponses.length; i++) {
    copyBody.appendParagraph(formResponses[i].getItem().getTitle().toString());
    copyBody.appendParagraph(formResponses[i].getResponse().toString());
    copyBody.appendParagraph(" ");

  }


// Save and close the temporary document
copyDoc.saveAndClose();

// Convert temporary document to PDF
var pdf = DriveApp.getFileById(copyId).getAs("application/pdf");

// Attach PDF and send the email
var subject = "Customer Survey";
var body = "Here is a New Customer Survey";
MailApp.sendEmail(email_address, subject, body, {htmlBody: body, attachments: pdf});

// Delete temp file
DriveApp.getFileById(copyId).setTrashed(true);
}

请帮忙!

1 个答案:

答案 0 :(得分:0)

这更多的是评论而不是答案,但我还没有足够的评论来评论。 检查你的触发器,有两种类型的FormSubmit触发器,一种用于表单,一种用于表单,如果你使用的是错误的触发器可能导致你的问题。