I'm trying to make a script for Google Sheets that uses a spreadsheet to create a form. I'm passing the values in the columns (loaded into the object 'dataObject') of the sheet into an Array of objects as shown.
  for (var i = 0; i < dataObject.length; i++)
  {
      dataObjectArray[i] = {
          question:    dataObject[i][3],
          type:        dataObject[i][4],
          help:        dataObject[i][5],
          choices:     dataObject[i][6],
          options:     dataObject[i][7],
          validation:  dataObject[i][8]
      }
  }
My goal is to then use the "question" property of each object to make a new item in my Google form. The problem I'm having is that depending on the question type, a completely different method is required to make the form.
The first thing I tried was making a dictionary of functions like so:
 var form = FormApp.create('Foo'); 
 var formDictionary = {
    "Text": function(){form.addTextItem();},
    "Paragraph Text": function(){form.addParagraphTextItem();},
    "Multiple Choice": function(){form.addMultipleChoiceItem();},
    "Checkboxes" : function() {form.addCheckboxItem();},
    "Choose from a list": function(){form.addListItem();},
    "Scale": function(){form.addScaleItem();},
    "Grid": function(){form.addGridItem();},
    "Date": function(){form.addDateItem();},
    "Time": function(){form.addDateTimeItem();}
  };
And then I would call the form creation function like so:
   for (var i = 1; i < dataObjectArray.length; i++){
    formDictionary[dataObjectArray[i].question]();
  }
At the moment, I'm receiving the error:
TypeError: Cannot find function undefined in object [object Object]. (line 113, file "Code")
I know that there are probably more than a few problems with what I have tried (I have caught a few of them myself), but I can't find a better solution.
I'd like to avoid switch statments if possible, though I'll use them if they're my only choice.
 
     
    