Tuesday 6 June 2023

Auto close Google Form after X responses

The following Google Apps Script is designed to automatically close a Google Form once it has reached the number of responses you specify.

Use Apps Script code to automatically close a Google Form
Use Apps Script code to automatically close a Google Form

 

Instructions

  1. Copy the code into your Google Form Response Sheet > Extensions menu > Apps Script.
  2. Create a 'form submit' trigger in order to connect the Apps Script code with the Google Form.
  3. Update the value of 'CLOSE_FORM_WHEN_RESPONSES_REACHES' in the code to the limit you want before the Form is switched off.
  4. Click the Save button and you are done.

 
 

Limitation

  • It is possible 2 people could submit the Form at exactly the same time, meaning both of their responses would be (successfully) recorded before it closed.

The Code

The process of turning off the Google Form so it no longer accepts responses is relatively simple and we pop this in an 'if' statement so that it only runs when we want it to:

if (numberOfRows >= CLOSE_FORM_WHEN_RESPONSES_REACHES) {

    // get the Url of the Form
    var formURL = ss.getFormUrl();

    // open the Form
    var form = FormApp.openByUrl(formURL);

    // disable Accepting responses
    form.setAcceptingResponses(false);
    Logger.log("This form is no longer accepting responses")

}


Download

Auto close Google Form after X responses download (please use 'Overview' > 'Make a copy' for your own version).

No comments:

Post a Comment