Linus Nox
Linus Nox

Reputation: 77

Populate Google Spreadsheet from Form using Google App Script

I create a Google Spreadsheet and a Google Form via the Google App Script and want to get all the responses from the form automatically added to a sheet in my spreadsheet.

This option is possible if you do it manually, but I can't find an option to do it automatically in Google App Script.

I have seen some answers here on StackOverflow to populate forms from spreadsheets, but I need the inverse case.

Is that possible?

Upvotes: 1

Views: 2136

Answers (2)

Mike Steelson
Mike Steelson

Reputation: 15328

Google Forms has a setting that allows you to send your form responses to Google Sheets. This can be a new or existing spreadsheet.

In your chosen form, click on the responses tab.

  • Click on the three dots button located next to the Google Sheets icon.
  • Click on Select responses destination from the drop.
  • Select existing spreadsheet.

If you want to do it by script, as the form is already created

var form = FormApp.openById('id of the form');
form.setDestination(FormApp.DestinationType.SPREADSHEET, 'id of the spreadsheet);

destination type

Upvotes: 1

doubleunary
doubleunary

Reputation: 19220

Use Form.setDestination(), like this:

const ss = SpreadsheetApp.create('Response destination spreadsheet');
const form = FormApp
  .create('New form name')
  .setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());

Upvotes: 2

Related Questions