Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barrieroberts/5340ea3a460f58c053684b4edd01aeb5 to your computer and use it in GitHub Desktop.
Save barrieroberts/5340ea3a460f58c053684b4edd01aeb5 to your computer and use it in GitHub Desktop.
Create & update a question on a Google Form from data on a Google Sheet
function createForm() {
var form = FormApp.create("New form");
var formQ1 = form.addMultipleChoiceItem();
formQ1.setTitle('Where do you want to go on holiday?');
formQ1.setChoiceValues(['Seville', 'London']);
}
function createFormFromData() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("newQ");
var question = ss.getRange(2, 1, 1, 1).getValue();
var options = ss.getRange(4, 1, 2, 1).getValues();
var form = FormApp.create("New form");
var formQ1 = form.addMultipleChoiceItem();
formQ1.setTitle(question);
formQ1.setChoiceValues(options);
}
function updateFormFromData() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("updateQ");
var question = ss.getRange(2, 1, 1, 1).getValue();
var options = ss.getRange(4, 1, 2, 1).getValues();
var form = FormApp.openById('1ANwqzhIGiYQf3a4VBa_Ul2Et16NHwROupCoxURrKPxo');
var allItems = form.getItems();
var formQ1 = allItems[0].asMultipleChoiceItem();
formQ1.setTitle(question);
formQ1.setChoiceValues(options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment