Archive for 2019
FORM_OPEN_DATE = "2015-12-10 10:10";
FORM_CLOSE_DATE = "2015-12-20 23:30";
RESPONSE_COUNT = "20";
/* Mengatur Pemicu Waktu dan Akses Form */
function Initialize() {
deleteTriggers_();
if ((FORM_OPEN_DATE !== "") &&
((new Date()).getTime() < parseDate_(FORM_OPEN_DATE).getTime())) {
closeForm();
ScriptApp.newTrigger("openForm")
.timeBased()
.at(parseDate_(FORM_OPEN_DATE))
.create();
}
if (FORM_CLOSE_DATE !== "") {
ScriptApp.newTrigger("closeForm")
.timeBased()
.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]);
}
}
/* Mengirim email ke pembuat form saat status form berubah*/
function informUser_(subject) {
var formURL = FormApp.getActiveForm().getPublishedUrl();
MailApp.sendEmail(Session.getActiveUser().getEmail(), subject, formURL);
}
/*Mengizinkan akses ke google form*/
function openForm() {
var form = FormApp.getActiveForm();
form.setAcceptingResponses(true);
informUser_("Google Form dapat anda akses sekarang");
}
/*Menghentikan akses ke google form saat google form sudah full peserta atau waktunya sudah lewat*/
function closeForm() {
var form = FormApp.getActiveForm();
form.setAcceptingResponses(false);
deleteTriggers_();
informUser_("maaf, Google form tidak bisa diakses lagi");
}
/* Jika total partisipan sudah melewati batas, maka google form ditutup*/
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));
}
Search Box
dfggfgf