appscript.dev
Automation Beginner Forms

Auto-close a form at a capacity limit

Stop accepting Northwind RSVPs once a quota is hit — no overselling the workshop.

Published Jul 29, 2025

Northwind runs hands-on workshops with a hard cap — the room only seats fifty. A Google Form collects the RSVPs, but a form happily accepts response number fifty-one, and number sixty. By the time anyone notices, ten people have been promised a seat that does not exist, and someone has to send the awkward emails.

This automation watches the response count and closes the form the moment it reaches the limit. It swaps in a friendly “we’re full” message so latecomers see a clear notice instead of an open form, and it only acts while the form is still accepting responses, so it is harmless to leave running.

What you’ll need

  • A Google Form collecting the RSVPs, and its file ID.
  • A capacity number — the seat limit for the event.
  • Nothing else: the script reads the response count and closes the form itself.

The script

// The RSVP form to monitor.
const FORM_ID = '1abcFormId';

// Maximum responses to accept before closing the form.
const CAPACITY = 50;

// Message shown once the form is closed.
const CLOSED_MESSAGE = "We're full — thanks for your interest.";

/**
 * Closes the RSVP form once its response count reaches CAPACITY, and
 * replaces the closed-form message with a friendly notice.
 */
function checkCapacity() {
  const form = FormApp.openById(FORM_ID);

  // 1. Count the responses received so far.
  const count = form.getResponses().length;

  // 2. Close the form only if it is full AND still open — so a closed
  //    form is left untouched and the message is set just once.
  if (count >= CAPACITY && form.isAcceptingResponses()) {
    form.setAcceptingResponses(false);
    form.setCustomClosedFormMessage(CLOSED_MESSAGE);
    Logger.log('Capacity reached (' + count + ') — form closed.');
  } else {
    Logger.log('Responses: ' + count + ' of ' + CAPACITY + '.');
  }
}

How it works

  1. checkCapacity opens the form by ID and reads getResponses().length — the total number of submissions so far.
  2. It checks two things together: that the count has reached CAPACITY, and that the form is still accepting responses.
  3. The second check matters. It means the close logic runs exactly once — on the first run that finds the form full — rather than re-setting the message on every later run.
  4. If both are true, it calls setAcceptingResponses(false) to close the form and setCustomClosedFormMessage to show the “we’re full” notice.
  5. Either way it logs the current count, so the execution history shows how the registration is filling up.

Example run

A scheduled run while registration is open:

ResponsesForm stateAction
38AcceptingLogs “Responses: 38 of 50.” — no change
50AcceptingCloses the form, sets the closed message
50ClosedLogs “Responses: 50 of 50.” — no change

Once the form is closed, anyone visiting the link sees “We’re full — thanks for your interest.” instead of the questions.

Trigger it

This needs to run on a schedule throughout the registration window:

  1. In the Apps Script editor, open Triggers (the clock icon).
  2. Click Add Trigger.
  3. Choose checkCapacity, event source Time-driven, type Minutes timer, and pick Every 5 minutes.
  4. Remove the trigger once the event is over so it stops running.

For an instant close instead of a five-minute window, attach an On form submit trigger to the form so checkCapacity runs after every single submission.

Watch out for

  • A time-driven trigger leaves a gap. Between two five-minute runs the form can take a handful of extra responses — use an on-submit trigger if even one over the limit is unacceptable.
  • The count includes every response ever submitted. If you reuse the form for a second event without clearing old responses, it will start already “full”.
  • A closed form cannot be reopened by this script — it only ever closes. Reopen it by hand from the form’s settings if you raise the cap.
  • getResponses() loads every response object just to count them. For a form with thousands of entries that is wasteful but still fast enough for this use; it is worth knowing if you adapt the script.
  • Remember to delete the trigger after the event. A forgotten Minutes timer keeps running and quietly consumes your daily trigger quota.

Related