简体   繁体   English

提交表格损坏

[英]Broken Submission Form

I have a survey form that we use for our clients. 我有一份供客户使用的调查表。 It is a series of multiple choices questions, and a few text field entries. 它是一系列的多项选择题和一些文本字段条目。 At the end, you click "submit" and an email is sent containing all the responses to our Quality Manager. 最后,您单击“提交”,然后会发送一封电子邮件,其中包含对我们质量经理的所有答复。 Recently, the form stopped working, and I found many people who successfully fixed the issue by changing docslist to DriveApp. 最近,该表格停止工作,我发现许多人通过将docslist更改为DriveApp成功解决了该问题。 However, now I am getting the error: 但是,现在我得到了错误:

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

The entire code reads as follows: 整个代码如下:

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

Please help! 请帮忙!

This is more of a comment than an answer, but I dont have enough rep to comment yet. 这更多的是评论,而不是答案,但是我没有足够的代表评论。 Check your trigger, there is two types of FormSubmit triggers, one for sheets and one for forms, if you are using the wrong one that could be what is causing your issues. 检查触发器,有两种类型的FormSubmit触发器,一种是用于工作表的触发器,另一种是用于表单的触发器,如果​​您使用的错误触发器可能是导致问题的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM