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.

How to use Google Forms to limit checkboxes

If you want to just limit the number of checkboxes a respondent can select, no script is needed! Instead, there’s a default feature in Google Forms called “response validation,” and there’s an option for checkbox questions to limit how many responses can be selected. Let’s go through how.

Step 1: Create a checkbox question

First, create a new question and click the dropdown to select the Checkboxes format. With this, respondents can normally select as many options as they please in their answer. However, we’ll change that.

Step 2: Click “Response validation”

Now, click the “More” option (the three dots in the bottom right).

From this menu, click “Response validation.” This feature essentially sets specific parameters for the question. 

Step 3: Limit your checkbox question as you please

The response validation field will appear at the bottom of the question.

First, there will be a dropdown where you can select the rule you want to follow. You have three options: “Select at least,” “Select at most,” and “Select exactly.” Since we’re trying to limit responses, we would want to choose one of the latter two options.

After this, there’s a field to enter the number, which is where you’ll enter how many responses the respondent is limited to. There’s also a field to enter error text in case a user doesn’t follow the rule. If you decide to remove this rule, there’s an “X” on the right you can click.

With that, you’ve limited responses for a checkbox question in Google Forms!

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