Google Forms AutomationDifficulty: Intermediate⚡ On Form Submit

Automatically Close Google Form When Max Submissions Reached

Tracks event registrations or survey entries and automatically closes the Google Form and displays a custom "Event Sold Out" message when capacity is reached.

Required OAuth Scopes: https://www.googleapis.com/auth/forms
Code.gs (Apps Script V8 Runtime)
function checkMaxFormSubmissions() {
  const maxLimit = 100;
  const form = FormApp.getActiveForm();
  const count = form.getResponses().length;
  
  if (count >= maxLimit) {
    form.setAcceptingResponses(false);
    form.setCustomClosedFormMessage('Registration is now closed. We have reached maximum capacity (100 attendees).');
  }
}

Line-by-Line Code Explanation

Line 2-4: Specifies maximum attendee threshold and checks total response count.
Line 6-8: Closes form and posts a custom message when limit is reached.

Step-by-Step Setup & Deployment

  1. Open Google Forms > 3 dots menu > Script editor.
  2. Paste the code and set an onFormSubmit trigger.

Best Practices for Quota & Rate Limit Management

When deploying this automation in Google Workspace, adhere to these operational principles:

  • Batch Reads & Writes: Never execute getValue() or setValue() inside loops. Read ranges into memory in 1 call, process arrays in V8 memory, and commit changes with a single setValues() call.
  • Execution Timeouts: Apps Script terminates scripts exceeding 6 minutes. For multi-thousand row datasets, implement batch pagination with resume timestamps stored in PropertiesService.
  • OAuth Permissions: Scope your manifest (appsscript.json) narrowly to prevent security prompts from alarming external team members.

Frequently Asked Questions

Is Google Apps Script completely free to use?

Yes. Google Apps Script is built into all free Google accounts and Google Workspace editions. There are no server fees or subscription costs for running scripts within daily quotas.

Can I run this script on an automated schedule without keeping my computer on?

Yes. Time-driven triggers execute on Google's cloud infrastructure. Your script will run reliably even when your computer is closed or offline.

More Google Forms Automation Snippets