0

Hi I am looking to add questions to google form from google sheet. I have already figured a way of adding choices.

The sheet looks like this with the column header being the questions and everything under the header to be single choice answers to each question (these are just two of 60-70 questions),

enter image description here

How do I start from a blank form like below? enter image description here

I have got the below code to update the answers,

function updateForm(e){

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var sheetName = sheet.getSheetName();
  var getCol = e.range.getColumn(); 

  if(sheetName == 'Names' && 1){

  var nameValues = sheet.getRange('A2:A10').getValues(); // Get name values

  var form = FormApp.openById('---------');  // ID of form
  var formItems = form.getItems();
  var question = formItems[2].asListItem(); // Get the second item on the from 

  var names = []

  for(var x = 1; x < nameValues.length; x++){

    if(nameValues[x][0] != ""){ // Ignores blank cells
     names.push(question.createChoice(nameValues[x][0])) // Create an array of choice objects
   } 
  }
  var setQuestion1 = question.setChoices(names); // Update the question
  }
}

Any guidance on helping input the questions automatically on the google form is appreciated!

Mishal
  • 450
  • 9
  • 27
  • If you're starting from a blank form that you already created then you can get the id from it or if you wish you could use `const form=FormApp.create(title);` – Cooper Mar 23 '20 at 17:52
  • You really need to ask a specific question. `Any guidance on helping` is not a question. – Cooper Mar 23 '20 at 17:54
  • Thank you for your top on creating a new form - grateful for this. I am looking to add questions with answer options based on the google sheet. Any guidance on where I can start looking through documentation would be helpful. – Mishal Mar 23 '20 at 18:03
  • Hi @Tedinoz I have found a way to add the options - I am looking to add the questions on google for from google sheets – Mishal Mar 23 '20 at 22:25
  • Did you even **read** that Q&A? You need to use `addListItem`[Doc](https://developers.google.com/apps-script/reference/forms/form?hl=en#addlistitem) to "[append] a new question item that allows the respondent to select one choice from a drop-down list" plus `setChoiceValues` [Doc](https://developers.google.com/apps-script/reference/forms/list-item?hl=en#setchoicevaluesvalues) to "[set] the choices for an item from an array of strings." The [answer](https://stackoverflow.com/a/55697439/1330560) by @PeterT explains _exactly_ how to do this. – Tedinoz Mar 23 '20 at 22:59
  • I did go through the question but might not have picked up on ```addListItem``` thank you for pointing this out! I will test and see how it works. Appreciate the guidance – Mishal Mar 23 '20 at 23:37

0 Answers0