how could I allow responses to a google form link within a certain time period daily? Example: form responses are only open daily from 830am to 3pm?
thank you
i want to allow google forms responses within a certain time range daily.
this is the example link: https://docs.google.com/forms/d/e/1FAIpQLScTb_OSCAh0wr5sWznehdwD6NOHbJ6uBzGPXUFuxrPToqtEHw/viewform
CodePudding user response:
I believe your goal is as follows.
- You want to open your Google Form at 08:30.
- You want to close your Google Form at 15:30.
- You want to run this every day.
In this case, how about the following sample script?
Sample script:
Please copy and paste the following script to the script editor of your Google Form, and save the script.
When you run init()
with the script editor, a time-driven trigger is installed. This trigger automatically runs the function installTimeDrivenTrigger()
every day. When this function is run, start()
and end()
functions are installed as the time-driven trigger.
start()
enable Google Form at 08:00. And, end()
disable Google Form at 15:00. And, after the next day, the function installTimeDrivenTrigger()
is automatically run.
const deleteTriggers_ = e => ScriptApp.getScriptTriggers().forEach(t => {
if (e.includes(t.getHandlerFunction())) ScriptApp.deleteTrigger(t);
});
const start = _ => FormApp.getActiveForm().setAcceptingResponses(true);
const end = _ => FormApp.getActiveForm().setAcceptingResponses(false).setCustomClosedFormMessage("Closed.");
function installTimeDrivenTrigger() {
deleteTriggers_(["start", "end"]);
const time1 = new Date();
time1.setHours(8, 30, 0);
const time2 = new Date();
time2.setHours(15, 0, 0);
ScriptApp.newTrigger("start").timeBased().at(time1).create();
ScriptApp.newTrigger("end").timeBased().at(time2).create();
}
// Please run this script. By this, installTimeDrivenTrigger() is run 00:00 - 01:00 every day.
function init() {
deleteTriggers_(["installTimeDrivenTrigger"]);
ScriptApp.newTrigger("installTimeDrivenTrigger").timeBased().everyDays(1).atHour(0).create();
}
- In this sample, when the user accesses the Google Form from 15:00 to 08:30, "Closed." is shown. If you want to change this message, please modify the above script.
Note:
- In this modification, when the function name is changed, the script might not be able to be used when the function names in the script are not changed. Please be careful about this.