Labels

Bollywood (283) Education (162) General News (21) Technology (120) Top 10 (206)

Friday 13 May 2016

How to Schedule your Google Forms and Limit Submissions

Schedule Your Google Forms And Limit Submission

You can easily schedule your google forms. At a certain limit of data, they will automatically close and open. In the same way, After a certain no. of entries have been recieved through the form, the google script can be configured to turn off the your form.
1. Log on on to google drive and open the already existing google form/create new form.
2. Inside the editor of forms, clcik on tools then script editor copy paste the below code.
3. While opening of the script editor, go to file => project setting and be sure that the right time zone is selected.
4. Set the Response_Count equivalent to the total no. of entries that you would like to receive after automatically closing of the form. If you don't want to set a limit, set this value to blank.
5. Set the form's closeing 7 opening dates in a line #1 & #2in YYYY-MM-DD HH:MM format. If you don't have the date of open & close the form, just set this value to blank.
6. Press ctrl+s (cmd+s on Mac) to save the script & choose run then initailize to authorize the script.
Schedule your Google Forms and Limit Submissions

The google script will now run in the background & you'll get a notification through email when one of the condition is match & google form is closed for new responses.

Google Script for Scheduling Google Forms

FORM_OPEN_DATE   =  "2014-12-20 08:00";
FORM_CLOSE_DATE  =  "2014-12-25 23:30";
RESPONSE_COUNT   =  "100";
/* Web tutorial: http://labnol.org/?p=20707  */
/* Initialize the form, setup time based triggers */
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]);
  }
}
/* Send a mail to the form owner when the form status changes */
function informUser_(subject) {
  var formURL = FormApp.getActiveForm().getPublishedUrl();
  MailApp.sendEmail(Session.getActiveUser().getEmail(), subject, formURL);  
}
/* 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));
}
If you want to close your google form for new responses, go to google drive, open from and click on the "accepting responses" option. You can reopen the form by checking the "not accepting responses" button.

0 comments:

Post a Comment