我喜欢Google表单,我可以和他们一起玩几个小时。我花了好几天的时间试图解决这个问题,寻找答案。这是在我的头上。我看到过类似的问题,但似乎没有任何帮助我找到答案。我们在一家咖啡厅工作,并在Google表单上创建了预订表单。这是很容易的部分。咖啡厅只能接受上午10:30前的预购。我希望表格在上午7点开放,每天上午10点30分关闭,以阻止人们在咖啡馆无法处理他们的订单时预先订购。我使用http://labnol.org/?p=20707的非常有用的教程来启动我,我已经添加并将其搞砸了,并设法返回到目前的外观。它不工作,我无法绕过它。有一次,我设法关闭它,但是我无法重新启用它!我发现它非常令人沮丧,任何解决这个问题的帮助都很棒。对我来说,这似乎很简单,因为它只需要在每天的特定时间打开和关闭。我不知道!请帮我一个人吗?每天自动打开和关闭的Google表单
FORM_OPEN_DATE = "7:00";
FORM_CLOSE_DATE = "10:30";
RESPONSE_COUNT = "";
/* Initialize the form, setup time based triggers */
function Initialize() {
deleteTriggers_();
if ((FORM_OPEN_DATE !== "7:00") &&
((new Date()).getTime("7:00") < parseDate_(FORM_OPEN_DATE).getTime ("7:00"))) {
closeForm("10:30");
ScriptApp.newTrigger("openForm")
.timeBased("7:00")
.at(parseDate_(FORM_OPEN_DATE))
.create(); }
if (FORM_CLOSE_DATE !== "10:30") {
ScriptApp.newTrigger("closeForm")
.timeBased("10:30")
.at(parseDate_(FORM_CLOSE_DATE))
.create(); }
if (RESPONSE_COUNT !== "") {
ScriptApp.newTrigger("checkLimit")
.forForm(FormApp.getActiveForm())
.onFormSubmit()
.create(); } }
/* Delete all existing Script Triggers */
function deleteTriggers_() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
/* Allow Google Form to Accept Responses */
function openForm() {
var form = FormApp.getActiveForm();
form.setAcceptingResponses(true);
informUser_("Your Google Form is now accepting responses");
}
/* Close the Google Form, Stop Accepting Reponses */
function closeForm() {
var form = FormApp.getActiveForm();
form.setAcceptingResponses(false);
deleteTriggers_();
informUser_("Your Google Form is no longer accepting responses");
}
/* If Total # of Form Responses >= Limit, Close Form */
function checkLimit() {
if (FormApp.getActiveForm().getResponses().length >= RESPONSE_COUNT) {
closeForm();
}
}
/* Parse the Date for creating Time-Based Triggers */
function parseDate_(d) {
return new Date(d.substr(0,4), d.substr(5,2)-1,
d.substr(8,2), d.substr(11,2), d.substr(14,2));
}
如果精度很关键,基于时间的触发器将不够用,因为触发器不能保证在指定的确切时间运行。 触发器通常定义触发后的时间,到时候必须落在每小时一班,所以10:30是不是一个触发的有效时间为15分钟之内。为了获得所需的精确度,您需要使用外部服务,该服务会在指定时间触发通知,并让您的应用程序通过将其部署为Web应用程序并将其网址用作Webhook来接收这些通知。复杂的东西。 –