How to Limit Responses in Google Forms Using Google Apps Script

July 14, 2021
How to Limit Responses in Google Forms Using Google Apps Script
Table of Contents
Table of Contents

Can you limit responses in Google Forms after a certain total has been reached automatically? Yes it is definitely possible to stop accepting responses in Google Forms. In this blog, I will show you how make Google Forms limit the number of responses using Google Apps Script. We are going to use the following fictitious example:

  • We are having a Cloud computing workshop.
  • But the hall that we have booked has a max capacity of 100 people.
  • People can register for the workshop through a Google Form.
  • The organizing Team wants to make sure that there are only 100 responses in the Google Form.

So let’s get started on the steps to turn off Google Form responses.

If you need to refresh your knowledge on using Google Forms, click on the link given below.

Step 1: Sample Google Form

The form that I will be using is a Simple Registration form. (If you prefer working with click here).

The form contains the following details:

  1. Name of the Attendee
  2. Email Address of the Attendee
  3. Phone number of the Attendee
This is the Google Form that the Attendee will fill

Step 2: Write the Automation Script for the Google Form to stop accepting responses

While you are in the Form, launch the Google Forms' Apps Script Editor.

To do that:

(1) Click on 3 dots next to the Send button on the top right.

(2) Next click on the Script Editor option.

This brings up the Script Editor as shown below:

We have reached the Script Editor. Let’s Code.

function Limit_Responses() {
    
    let  max_responses = 8;
    let  form = FormApp.openById("17XDAjSnwB8gU0CIpiDLRv3Q7-Ozfro-n0pRDQOAEjuI");
    let  responses = form.getResponses();
  let len = responses.length;
  //Logger.log(len);
  if (len === max_responses){

    form.setAcceptingResponses(false);

  }

}
function Limit_Responses() {
    let  max_responses = 8;
    let  form = FormApp.openById("17XDAjSnwB8gU0CIpiDLRv3Q7-Ozfro-n0pRDQOAEjuI");
    let  responses = form.getResponses();

Here we are first declaring the maximum number of responses that you want in your Google Form. Next, we are going to get the form by ID. Then we are going to get the responses that are in the Google Form.

let len = responses.length;
//Logger.log(len);
if (len === max_responses){

    form.setAcceptingResponses(false);
     }

}

Here we get the length of the responses present in the Google Form.

Step 3: Limit Number of Responses in Google Forms by Adding a Trigger

In order to count the responses, we have to add a trigger, so that as soon a new response comes into the form, the count of the responses will get incremented by 1.

To add the trigger follow these steps:

  1. Click on the Triggers button.

2. To add the trigger click on Add Trigger.

3. Make the following changes in the trigger that you have made.

Here you have to select the Limit_Responses function. For the event type you have to select On form Submit.

After making the changes click on Save.

Now, the script will turn off responses in Google Form, as soon as they match the specified max responses. In practice, this will cause the Google Form to get locked and no longer accept responsesThe viewer will get a message to the tune of “this Google Form is no longer accepting responses”. Visually, it will look like this.

Here you can see that the form has shown a message that says that the form is no longer accepting responses. If you want custom messages for the form you can go back to the form and make the changes.

After some time maybe you want to open the Google Form again, to do that follow these steps :

  1. Click on responses

2. When the responses section is open in the Google Form, “Not Accepting Responses' ' will be visible in a red stripe with a slider button.

Turning Off the Google Form Response Limit Feature

Now that you know how to limit the number of responses in Google Forms, it is also important to know how to turn off this function. To open the form back for responses click on the button that says Not Accepting responses.

On clicking the Google Form will be open for responses.

If you prefer watching a video on how to limit responses in Google Forms, click on the link below.

This is all for this blog on how to stop accepting responses on Google Forms. I hope you have understood how to Limit Responses in Google Forms Using Google Apps Script. You can send your feedback to aryanirani123@gmail.com.

A previous version appeared at this link: https://aryanirani123.medium.com/limit-responses-in-google-forms-using-google-apps-script-64ea2d07342f

Great! Next, complete checkout for full access to Form Publisher Blog
Welcome back! You've successfully signed in
You've successfully subscribed to Form Publisher Blog
Success! Your account is fully activated, you now have access to all content
Success! Your billing info has been updated
Your billing was not updated