GAS AI BuilderApps Script Assistant Sign in

Make a real Google Form with code

Apps Script recipes › Email, Docs, Forms and PDF

Creates a Google Form once, keeps its ID, sends its responses to the project's Sheet and returns its links.

File Code.gs

function setupForm() {
  const props = PropertiesService.getScriptProperties();
  const id = props.getProperty('FORM_ID');
  if (id) {
    const form = FormApp.openById(id);
    return { url: form.getPublishedUrl(), editUrl: form.getEditUrl() };
  }
  const form = FormApp.create('Registration');
  form.setCollectEmail(true);
  form.addTextItem().setTitle('Full name').setRequired(true);
  form.addMultipleChoiceItem().setTitle('Session').setChoiceValues(['Morning', 'Afternoon']).setRequired(true);
  form.addParagraphTextItem().setTitle('Notes');
  form.setDestination(FormApp.DestinationType.SPREADSHEET, SHEET_ID);
  props.setProperty('FORM_ID', form.getId());
  return { url: form.getPublishedUrl(), editUrl: form.getEditUrl() };
}

Good to know

Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.

Use it in a project

More in Email, Docs, Forms and PDF

Fill a Doc template and save it as PDFCopies a Google Doc with {{placeholders}}, fills them in, saves a PDF in a folder and removes the copy.Send an HTML email from a templateThe email body is an HTML file with <?= name ?> fields; checks the daily email quota first.