这是我第一次编写谷歌应用程序脚本,我迫切需要帮助。
目的是建立一个研讨会报名表。根据已注册的人数,将发送一封电子邮件,通知您注册成功,或者是否已列入等待列表。
我从tutorial复制了代码。但需要帮助来获得表单回复的计数。现在看来是这样的:
function onFormSubmit(e) {
var timestamp = e.values[0];
var yourName = e.values[1];
var toAddress = e.values[2];
var subject = "Workshop Confirmation";
var emailBody = "Thank you for your submitted on " + timestamp
var num_response = COUNT_NUMBER_OF_RESPONSE // <-- need help here
var LIMIT = 15
if (num_response <= LIMIT) {
emailBody = emailBody + "\n\nYou are enrolled in the workshop";
}
else {
var wait = num_response - LIMIT
emailBody = emailBody + "\n\nThe workshop is full. You are #" + wait + " in the waiting list"
}
emailBody = emailBody + "\n\nThe details you entered were as follows: " +
"\nYour Name: " + yourName +
"\nYour Email: " + toAddress ;
MailApp.sendEmail(toAddress, subject,
emailBody, optAdvancedArgs);
}
我不知道如何在谷歌应用文档中找到正确的答案。任何帮助将不胜感激!
答案 0 :(得分:1)
从我在教程中看到的,这个脚本嵌入在电子表格中,因此最容易计算行数并减去1,因为标题...
有一种方法:getLastRow(),此链接中提到的文档应该为您提供足够的信息来编写您需要的几行代码...
测试:
function xx(){
var lr = SpreadsheetApp.getActiveSheet().getLastRow()-1;
Logger.log(lr);
}
答案 1 :(得分:1)
复合函数怎么样
FormApp.getActiveForm().getResponses().length
无需四处寻找电子表格(因为根据我的经验,电子表格并非始终是最新的,而表单是
)