Javascript Google Sheets脚本只处理一个文件
我试图让我们网站上的谷歌表单在用户填写表单时自动通知我们,然后返回他们在简明电子邮件中输入的数据。我不喜欢谷歌通知你的方式,它只是链接到你的表格来查看回复。我在网上搜索并找到以下代码:Javascript Google Sheets脚本只处理一个文件,javascript,google-sheets,google-forms,Javascript,Google Sheets,Google Forms,我试图让我们网站上的谷歌表单在用户填写表单时自动通知我们,然后返回他们在简明电子邮件中输入的数据。我不喜欢谷歌通知你的方式,它只是链接到你的表格来查看回复。我在网上搜索并找到以下代码: function sendFormByEmailPrayer(e) { // Remember to replace XYZ with your own email address var email = "admin@communionchapelefca.org"; // Optio
function sendFormByEmailPrayer(e)
{
// Remember to replace XYZ with your own email address
var email = "admin@communionchapelefca.org";
// Optional but change the following variable
// to have a custom subject for Google Docs emails
var subject = "Prayer Form Form Submitted";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var urlToDoc = SpreadsheetApp.getActive().getUrl();
var body = "";
body = body + "Link to Document: " + urlToDoc;
var message = body + "\n\n" + "";
// Credit to Henrique Abreu for fixing the sort order
for(var i in headers)
message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n";
// This is the MailApp service of Google Apps Script
// that sends the email. You can also use GmailApp here.
MailApp.sendEmail(email, subject, message);
// Watch the following video for details
// http://youtu.be/z6klwUxRwQI
// By Amit Agarwal - www.labnol.org
}
在表单上提交屏幕截图:
它在我的一个表单上非常有效,但当我将此工作代码复制并粘贴到其他6个表单上时,它根本不起作用。我如何让这项工作在我们的7个表格中运行?提前感谢。我找到了一个比上述代码更好的解决方案。如果使用新的Google Forms,可以添加一个“附加组件”(YourForm-->右上角的三个点-->附加组件)
从那里寻找它会自动发送带有标题的回复电子邮件。我花了大约5秒钟来设置每个表单。您是否在其他脚本中安装了“表单提交”触发器?在代码编辑器中,您需要单击“资源”菜单,选择“当前项目触发器”,然后添加新触发器,并选择函数名称。我在代码中没有看到任何特定于谷歌电子表格或表单的内容。如果代码在一个地方工作,而在另一个地方不工作,并且代码是通用的,那么它不能是脚本本身。是的,提交表单上的表单适用于所有其他脚本。是的,这就是为什么我感到困惑的原因。代码是如此的通用,它不可能是脚本,但我不知道是什么导致它。