Limit Responses in Google Forms Using Google Apps Script

Aryan Irani
4 min readApr 6, 2021



In this blog, I am going to show you how to limit responses in Google Forms 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.

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

Step1: 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:

  • Name of the Attendee
  • Email Address of the Attendee
  • Phone number of the Attendee
This is the Google Form that the Attendee will fill

Step2: Write the Automation Script

While you are in the For, launch the 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() {
max_responses = 5;
var form = FormApp.openById("17XDAjSnwB8gU0CIpiDLRv3Q7-Ozfro- n0pRDQOAEjuI");
var 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.

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

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

Step3: Add 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 as soon as the number of responses in the Google Form matches the max responses, the Google Form will get locked and no longer accept responses. 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.

Here you can add your custom messages

If you prefer watching the video, click on the link below.

This is all for this blog. I hope you have understood how to Limit Responses in Google Forms Using Google Apps Script. You can send your feedback to