Created
October 6, 2017 23:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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