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.
https://www.googleapis.com/auth/formsfunction 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
Step-by-Step Setup & Deployment
- Open Google Forms > 3 dots menu > Script editor.
- 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()orsetValue()inside loops. Read ranges into memory in 1 call, process arrays in V8 memory, and commit changes with a singlesetValues()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
Google Forms: Automated Dynamic Email Confirmation on Submit
Listens for Google Form submissions, extracts respondent name, email, and requested service, and dispatches a personalized HTML confirmation receipt immediately.
Google FormsPopulate Google Forms Dropdowns Dynamically from Spreadsheet
Reads dynamic inventory, available event time slots, or staff names from Google Sheets and automatically updates dropdown choices in an active Google Form.