Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
crazymovingco opened this issue Oct 15, 2018 · 2 comments

Comments

@crazymovingco
Copy link

Why is running the appscript giving this error?

@SableRaf
Copy link

SableRaf commented Oct 19, 2022

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
Copy link

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]();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants