stevenschmatz / export-google-form

:arrow_down_small: A small Google Apps Script file to export a form into a JSON file.
MIT License
106 stars 43 forks source link

TypeError: Cannot find function asDatetimeItem in object Item. (line 57, file "Code") #6

Open crazymovingco opened 5 years ago

crazymovingco commented 5 years ago

Why is running the appscript giving this error?

SableRaf commented 1 year ago

This is a case error. This script builds the constructor method from the item's type adding as as a prefix and Item as a suffix as seen below:

var itemTypeConstructorName = snakeCaseToCamelCase("AS_" + item.getType().toString() + "_ITEM"); 

The problem is that the itemType for date-time is DATETIME and not DATE_TIME so snakeCaseToCamelCase() returns asDatetimeItem() instead of asDateTimeItem() (with a capital T)

See the form API reference for item.

SableRaf commented 1 year ago

Here's how I fixed it:

  // Downcast items to access type-specific properties
  var typeString = item.getType().toString();
  if(typeString==='DATETIME') typeString='DATE_TIME' // handle the corner case of DATETIME 
  var itemTypeConstructorName = snakeCaseToCamelCase("AS_" + typeString + "_ITEM");  
  var typedItem = item[itemTypeConstructorName]();