appscript.dev
Automation Advanced Forms Gmail

Build a conditional intake-form router

Send long Northwind forms only to relevant respondents based on short pre-survey answers.

Published Sep 15, 2025

Northwind’s intake form tried to cover everyone — new clients, existing clients, vendors — in one long questionnaire. The result was a form so padded with “skip this section if it does not apply” instructions that respondents gave up halfway through, and the team got patchy answers from everyone.

This script splits intake into two steps. A short pre-survey asks only one thing: who are you? Based on that answer, the script emails the respondent a link to the right detailed form — and nothing else. Each person sees a form built for them, so it is shorter, clearer, and gets finished.

What you’ll need

  • A short Google pre-survey form with two questions: an email field and a “Who are you?” multiple-choice question whose options match the routes below.
  • Three (or more) detailed Google Forms — one per respondent type — and their shareable links.
  • Edit access to the pre-survey form, so you can attach the submit trigger.

The trigger

// Each pre-survey answer mapped to the detailed form it should send.
const ROUTES = {
  'New client': 'https://forms.gle/NEW_CLIENT_FORM',
  'Existing client': 'https://forms.gle/EXISTING_CLIENT_FORM',
  'Vendor': 'https://forms.gle/VENDOR_FORM',
};

// The exact titles of the two questions the script reads.
const ROLE_QUESTION = 'Who are you?';
const EMAIL_QUESTION = 'Email';

/**
 * Runs on every pre-survey submission. Reads the respondent's role and
 * email, then sends them the matching detailed form.
 */
function onFormSubmit(e) {
  // 1. Pull the answers out of the submission by question title.
  const role = e.namedValues[ROLE_QUESTION] && e.namedValues[ROLE_QUESTION][0];
  const email = e.namedValues[EMAIL_QUESTION] && e.namedValues[EMAIL_QUESTION][0];

  // 2. Bail out if either answer is missing — nothing to route.
  if (!role || !email) {
    Logger.log('Missing role or email — skipping.');
    return;
  }

  // 3. Look up the detailed form for this role.
  const next = ROUTES[role];
  if (!next) {
    Logger.log('No route for role: ' + role);
    return;
  }

  // 4. Email the respondent the link to their tailored form.
  GmailApp.sendEmail(email, 'A few more details', `Continue here: ${next}`);
}

How it works

  1. onFormSubmit runs automatically whenever someone submits the pre-survey, thanks to the form-submit trigger you attach below.
  2. The event object e carries namedValues, a map of question title to the answers given. The script reads the role and email by their question titles.
  3. If either answer is missing it logs the reason and stops — no email goes out for an incomplete submission.
  4. It looks the role up in the ROUTES map. An unrecognised role (a mismatch between the form options and the map keys) is logged and skipped.
  5. If a route is found, GmailApp.sendEmail sends the respondent a short message with the link to their detailed form.
  6. The respondent only ever receives the one form that applies to them, so the long all-in-one questionnaire is never needed.

Example run

Someone fills in the pre-survey:

EmailWho are you?
[email protected]Vendor

On submission, the script matches Vendor in ROUTES and sends:

To: [email protected] Subject: A few more details Body: Continue here: https://forms.gle/VENDOR_FORM

A respondent who picks “New client” instead gets the new-client form link, and a respondent whose answer is not in ROUTES gets nothing — the run just logs “No route for role”.

Trigger it

This must run on a form-submit trigger attached to the pre-survey:

  1. In the Apps Script editor, open Triggers (the clock icon).
  2. Click Add trigger.
  3. Choose onFormSubmit, set the event source to From form, and the event type to On form submit.
  4. Approve the authorisation prompt — the script needs permission to send email on your behalf.

Watch out for

  • The ROUTES keys must match the form’s multiple-choice options exactly, including capitalisation and spacing. A mismatch silently drops the respondent into the “no route” path.
  • namedValues keys are the question titles. Rename a question on the form and ROLE_QUESTION or EMAIL_QUESTION must change to match, or the lookup returns nothing.
  • If the email question is not a real email field, a typo in the address means the routing email bounces and the respondent is stuck. A required email-type question reduces this.
  • GmailApp.sendEmail counts against your daily Gmail send quota (500 for a consumer account, more for Workspace). A burst of pre-survey submissions can hit the limit.
  • The trigger must be attached to the pre-survey form, not the detailed forms. Attaching it to the wrong form means nothing routes.
  • Respondents can ignore the follow-up email. The script sends the link but cannot make anyone open it — chase non-responders separately if intake completion matters.

Related