Close Form At Limit

Google Forms can't stop at 50 sign-ups or at Friday 5pm on its own. closeFormAtLimit(form, {maxResponses, closeAt, message}) checks both and, when either is hit, stops accepting responses and shows your closed message.

When to use

  • Event sign-ups with a fixed number of seats
  • Applications or orders with a deadline
  • Surveys you want to close without remembering to do it

How to use this snippet

/** * Stop a form accepting responses once a cap or deadline is reached. * * @param {GoogleAppsScript.Forms.Form} form * @param {{maxResponses?: number, closeAt?: Date|string, message?: string}} opts * @return {boolean} true if the form was closed by this call */ function closeFormAtLimit(form, opts) { opts = opts || {}; if (!form.isAcceptingResponses()) return false; var count = form.getResponses().length; var full = opts.maxResponses && count >= opts.maxResponses; var late = opts.closeAt && new Date() >= new Date(opts.closeAt); if (!full && !late) return false; form.setCustomClosedFormMessage( opts.message || (full ? 'This form has reached its response limit. Thank you!' : 'This form is now closed. Thank you!') ); form.setAcceptingResponses(false); return true; }

Example

function checkSignupForm() { var form = FormApp.openById('YOUR_FORM_ID'); closeFormAtLimit(form, { maxResponses: 50, closeAt: '2027-02-12T17:00:00', message: 'Sign-ups are closed. See you there!' }); }

Run it from an installable On form submit trigger to catch the cap right away, and a time-driven trigger to catch the deadline.

Notes

  • It returns false and does nothing if the form is already closed, so running it often is safe.
  • closeAt uses the script's time zone when you pass a string without an offset.
  • To reopen, call form.setAcceptingResponses(true) and raise the cap.

Happy Coding!

NitroGAS Chrome Extension

Want this snippet handy inside the Apps Script editor? NitroGAS gives you free snippets — plus optional Co-Pilot when you want a boost (Day Pass — $3, or 1-week, 1-month, or yearly passes — no subscription). Happy Coding!

Get the Extension