【发布时间】:2018-10-01 19:56:31
【问题描述】:
我一直在为我的问题寻找解决方案,但一直没有找到,因此我在 Stack Overflow 中写下我的第一个问题。
我目前正在使用 Google Apps 脚本编写一个简单的程序,如果用户忘记在某个日期之前提交 Google 表单,它会向用户发送电子邮件提醒。现在我有 3 个不同的函数:onFormSubmit、scheduleTrigger 和 reminderEmail。以下是我目前写的代码:
/**
This function searches the Google Form for the date when the previous
session was held & the date when the next session will be held.
This function also calculates the date when to remind the user if they
forget to submit the Google Form. This reminder date is calculated to be 2
days after the date when the next session is held.
This function calls the next function: scheduleTrigger.
*/
function onFormSubmit(e) {
var form = FormApp.getActiveForm();
var frm = FormApp.getActiveForm().getItems();
var futureDate = new Date(e.response.getResponseForItem(frm[3]).getResponse());
var pastDate = new Date(e.response.getResponseForItem(frm[0]).getResponse());
var reminderDate = new Date(futureDate.setDate(futureDate.getDate() + 2));
futureDate.setDate(futureDate.getDate() - 2);
scheduleTrigger(reminderDate, futureDate, pastDate, form);
}
/**
This function schedules the reminder email trigger at a specific date. The
specific date is the reminder date that was calculated in the previous function.
This function calls the next function: reminderEmail.
*/
function scheduleTrigger(reminderDate, futureDate, pastDate, form) {
ScriptApp.newTrigger('reminderEmail(reminderDate, futureDate, pastDate, form)').timeBased().atDate(reminderDate.getFullYear(), reminderDate.getMonth(), reminderDate.getDate()).inTimezone('America/New_York').create();
}
/**
This function checks the submissions if the form has been submitted.
If there is no submission, then it sends out an email reminder.
*/
function reminderEmail(reminderDate, futureDate, pastDate, form) {
var count = 0;
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
if (itemResponse == futureDate) {
count++;
}
}
}
if (count != 2) {
MailApp.sendEmail("test@gmail.com",
"Submit Form Reminder",
"Hey! You didn't fill out the form yet!");
};
}
我遇到的问题是,每当我运行程序时,我都会收到一条错误消息,指出功能提醒电子邮件的“找不到所选功能”。我环顾四周并关注了以前为解决此问题而发布的帖子,例如重命名函数并使用全新的不同 Google From 重新启动,但没有任何效果。我还拥有脚本的完全所有权和授权,因此权限不应该成为问题。
如果您对如何解决此问题有任何想法,请告诉我。欢迎任何和所有反馈!如果我的问题有任何不清楚的部分,请告诉我。感谢您花时间阅读这篇冗长的文章。
【问题讨论】:
标签: google-apps-script google-forms