- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
项目 key :MyvPlY2KvwGODjsi4szfo389owhmw9jII
我正在尝试运行一个脚本,该脚本在每次提交表单时通过电子邮件发送我的表单内容。我完全按照下面这个链接中的说明进行操作,直到开始出现错误,并且我收到了更改脚本以按 ID 打开电子表格的建议:
http://www.snipe.net/2013/04/email-contents-google-form/
当我完成表格后,它应该将内容通过电子邮件发送到我的电子邮箱。
我现在遇到的问题是,通过表单值的函数不起作用。它正在返回错误
TypeError: Cannot read property "namedValues" from undefined. (line 15, file "Code")"
关于下面的代码:
for(var i in headers)
message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
我不太熟悉 Google Apps 脚本,所以我也不确定如何解决这个问题。你有什么推荐的吗?我在下面包含了整个脚本。
function sendFormByEmail(e)
{
// Remember to replace this email address with your own email address
var email = "sample@email.com";
var s = SpreadsheetApp.openById("1hOqnK0IVa2WT6-c-MY0jyGGSpIJIV2yzTXdQYX4UQQA").getSheets()[0];
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var subject = "New User Form";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
for(var i in headers)
message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
// Insert variables from the spreadsheet into the subject.
// In this case, I wanted the new hire's name and start date as part of the
// email subject. These are the 3rd and 16th columns in my form.
// This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
subject += e.namedValues[headers[2]].toString() + " - starts " + e.namedValues[headers[15]].toString();
// Send the email
MailApp.sendEmail(email, subject, message);
}
最佳答案
函数似乎未定义,因为“e”未作为函数上下文的一部分接收。您需要为提交表单设置触发器,并将信息发送到函数。您可以使用以下代码:
/* Send Confirmation Email with Google Forms */
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendConfirmationMail")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendConfirmationMail(e) {
try {
var ss, cc, sendername, subject, columns;
var header, message, value, textbody, sender, itemID, url;
// This is your email address and you will be in the CC
cc = "name@email.com";
// This will show up as the sender's name
sendername = "name to be displayed as sender";
// Optional but change the following variable
// to have a custom subject for Google Docs emails
subject = "Choose an approppiate subject";
// This is the body of the auto-reply
message = "";
ss = SpreadsheetApp.getActiveSheet();
columns = ss.getRange(1, 1, 1, ss.getLastColumn()).getValues()[0];
// This is the submitter's email address
sender = e.namedValues["Username"].toString();
// Only include form values that are not blank
for ( var keys in columns ) {
var key = columns[keys];
//Use this to look for a particular named key
if ( e.namedValues[key] ) {
if ( key == "Username" ) {
header = "The user " + e.namedValues[key] + " has submitted the form, please review the following information.<br />";
} else {
message += key + ' ::<br /> '+ e.namedValues[key] + "<br />";
}
}
}
}
textbody = header + message;
textbody = textbody.replace("<br>", "\n");
Logger.log("Sending email");
GmailApp.sendEmail(cc, subject, textbody,
{cc: cc, name: sendername, htmlBody: textbody});
} catch (e) {
Logger.log(e.toString());
}
}
关于javascript - Google Script 通过电子邮件发送表单值,错误 : cannot read property "namedValues",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28997714/
当我尝试在 Google 表格的脚本编辑器中运行基本脚本时,出现此错误: TypeError: Cannot read property "namedValues" from undefined. (
我使用 Java 访问 Alfresco 内容服务器,通过它的 Web 服务 API 将一些内容导入其中。内容应将一些 NamedValue 属性设置为 UTF-8(西里尔字母)字符串。我一直收到 S
项目 key :MyvPlY2KvwGODjsi4szfo389owhmw9jII 我正在尝试运行一个脚本,该脚本在每次提交表单时通过电子邮件发送我的表单内容。我完全按照下面这个链接中的说明进行操作,
我有一个简单的脚本,可以通过电子邮件发送 Google Drive 表单提交的结果。表单中的一个问题有多项选择复选框。我正在使用 e.namedValues 获取答案数组,以便我可以通过电子邮件发送给
我有一个非常基本的 Google Apps 表单,其中包含两个问题,资源(具有两个选项的单选按钮)和名称(文本字段)。我想在提交时选择表单值,所以我设置了一个触发器(在表单提交时)来调用一个函数: f
试图找出我哪里出错了。我不是编码员,但正在重复使用我用过的另一个 Google 工作表中的代码。 我试图在提交填充此 Google 工作表的表单时触发发送电子邮件。 这是公开表:https://doc
我是一名优秀的程序员,十分优秀!