Google Form - Scheduling



Scheduling in Google Form

      The function of scheduling is to allow respondent accessing the form for the specific time and vice versa.   It can be used for a test and other similar thing to respondents.You need to create a form first though on your google account.Then you could follow these steps below to setup the timing of schedule :



1.      Open the form that need to be scheduled. Click the 3 dots next to SEND button, then click Script editor as shown in Figure 1: 
Figure 1. Form

Then the monitor will show up an editor layer as Code.gs as shown in Figure 2 :
 
Figure 2. Script Editor

You can do as possible as some experiments by coding in this editor layer. 

2.   Here is the structure of codes for scheduling, you have to put it into myFunction() : 

var FORM_OPEN_DATE   =  new Date(2017, 3-1, 23, 21, 0);
  var FORM_CLOSE_DATE  =  new Date(2017, 3-1, 23, 21, 15);
    var now = new Date();

  deleteTriggers(); 
  
  if ((now.valueOf() < FORM_OPEN_DATE.valueOf())) {
    closeForm();

    ScriptApp.newTrigger("openForm")
    .timeBased()
    .at(FORM_OPEN_DATE)
    .create();

    ScriptApp.newTrigger("closeForm")
    .timeBased()
    .at(FORM_CLOSE_DATE)
    .create();
  }
   
  else if ((now.valueOf() >= FORM_OPEN_DATE.valueOf())
&& (now.valueOf() < FORM_CLOSE_DATE.valueOf())){
    openForm();

    ScriptApp.newTrigger("closeForm")
    .timeBased()
    .at(FORM_CLOSE_DATE)
    .create();
  }

  else {
    closeForm();

    ScriptApp.newTrigger("closeForm")
    .timeBased()
    .at(FORM_CLOSE_DATE)
    .create();
  }
 
}


function deleteTriggers() { 
  var triggers = ScriptApp.getProjectTriggers(); 
  for (var i in triggers) {
    ScriptApp.deleteTrigger(triggers[i]);
  }
}

function openForm() {
  var form = FormApp.getActiveForm();
  form.setAcceptingResponses(true);
}

function closeForm() { 
  var form = FormApp.getActiveForm();
  form.setAcceptingResponses(false);
  deleteTriggers();
}
 

 

Change the schedule by determining the deadline needed in FORM_OPEN_DATE and FORM_CLOSE_DATE variables.  The basic format of date is Date(year, month-1, day, hour, minute, second).

3.      After coding the schedule, you need to run those codes by clicking Run in the menu bar.
4.    You need to take a look for the result by accessing the form before and after open date, and after close date. It supposed to work well if you follow those steps carefully.



Explanation :


  • IF-ELSE clause is a structure to compare between now and the open date as well as the close date. This comparison is important to define status when you running the script, then system will execute the codes in that clause. There are 3 types of status needed, the first status is before open date, then the status between open date and close date, and the last status is after close date.
  • Trigger is a stored procedure that will automatically execute commands. Thus, you need trigger to help you for updating the status of the form. You have to place this trigger into IF-ELSE clause. It will update the status to open or close the form once you run all of the script, no need to run it manually. When the time pass close date, google form will close the form and inform respondents that it’s already closed and they entitled for access it.
  •  deleteTriggers() is used to delete all of triggers that running in the form. This method has to be executed at the first time before running other method to prevent the heap of triggers when you rerun codes in myFunction().

 

Comments