-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCode.gs
70 lines (59 loc) · 2.19 KB
/
Code.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* --------------------------
* Google Forms Auto-Close
* --------------------------
*
* Close a Google Form automatically.
*
* All you have to do is:
* 1. add a script to your current form
* 2. copy/paste the code from my project
* 3. edit FORM_ID (line 22)
* 4. edit FORM_CLOSE_DATE (line 25)
* 5. Save and run the "Initialize" function
* 1. This auto-creates a trigger to run the script for you on the date/time you entered
* 6. Why would you use this script and not an add-on?
* 1. you can see what it actually does
* 2. it isn't written by an unknown 3rd party :)
*
*/
/* Set the form_id using the unique code from the Form's edit URL (NOTE: id from the view URL does not work) */
FORM_ID = "1234567890abcdefghijklmnopqrstuvwxyz";
/* Set the form’s close date in YYYY-MM-DD HH:MM format. */
FORM_CLOSE_DATE = "YYYY-MM-DD HH:MM";
/***************************************************/
/******** DO NOT EDIT BELOW THIS LINE **************/
/***************************************************/
/* Initialize the form, setup time based triggers */
function Initialize() {
deleteTriggers_();
if (FORM_CLOSE_DATE !== "") {
ScriptApp.newTrigger("closeForm")
.timeBased()
.at(parseDate_(FORM_CLOSE_DATE))
.create();
}
}
/* Delete all existing Script Triggers */
function deleteTriggers_() {
var triggers = ScriptApp.getProjectTriggers();
for (var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
}
/* Send a mail to the form owner when the form status changes */
function informUser_(subject) {
var formURL = FormApp.openById(FORM_ID).getPublishedUrl();
MailApp.sendEmail(Session.getActiveUser().getEmail(), subject, formURL);
}
/* Close the Google Form, Stop Accepting Reponses */
function closeForm() {
var form = FormApp.openById(FORM_ID);
form.setAcceptingResponses(false);
deleteTriggers_();
informUser_("Your Google Form is no longer accepting responses");
}
/* 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));
}