英文:
Installable trigger not getting created
问题
关于可安装触发器的新手问题:我有一个Google表单,它将响应存储在工作表中。我有一个与工作表绑定的脚本,我想对响应进行一些处理并向表单提交者发送电子邮件。当我在编辑器中执行我的测试'onFormSubmit'函数时,它能正常工作(发送电子邮件),但触发器未出现在触发器列表中,并且当提交新表单时,我的函数不会执行。我漏掉了什么?
function onFormSubmit(e) {
Logger.log('Hello World');
MailApp.sendEmail({
to: "me@xyz.org",
subject: "Testing",
htmlBody: "This is a test email"
});
}
function createFormSubmitTrigger(e) {
ScriptApp.newTrigger("onFormSubmit")
.forForm(form)
.onFormSubmit()
.create();
}
英文:
Newbie question about installable triggers: I have a Google form which stores responses in a worksheet. I have a script bound to the worksheet where I want to do some manipulation of the responses and send an email to the form submitter. My test 'onForumSubmit' function works correctly (sends an email) when I execute in the editor, however the trigger does not appear in the Triggers list, and my function does not execute when a new form is submitted. What am I missing?
function onFormSubmit(e) {
Logger.log('Hello World');
MailApp.sendEmail({
to: "me@xyz.org",
subject: "Testing",
htmlBody: "This is a test email"
});
}
function createFormSubmitTrigger(e) {
ScriptApp.newTrigger("onFormSubmit")
.forForm(form)
.onFormSubmit()
.create();
}
答案1
得分: 2
一个可安装的“在表单提交时触发器”只需要创建一次。一旦创建好,它将在每次提交表单响应时运行。
您引用的createFormSubmitTrigger()
函数创建了一个用于表单的触发器。您说脚本项目绑定到了一个电子表格,所以原始代码不会起作用,因为您需要一个用于电子表格的触发器。虽然两种类型的文件都有“在表单提交时触发”的触发器,但它们需要不同的创建代码,并且将使用不同的事件对象e
运行。
由于触发器只需要创建一次,最简单的创建方法是按照说明中所示手动创建它。
英文:
An installable "on form submit" trigger only needs to be created one time. Once it is in place, it will run whenever a form response is submitted.
The createFormSubmitTrigger()
function you quote creates a trigger for a form. You are saying that the script project is bound to a spreadsheet, so that code will not work as is, because you need a trigger for a spreadsheet. There is an "on form submit" trigger for both kinds of files, but they require different creation code, and will run with a different event object e
.
Since the trigger only needs to be created once, the easiest way to create it is to do it manually as shown in the instructions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论