DylanRaub
DylanRaub

Reputation: 3

I get "Cannot find function asParagraghTextItem in object Item" from a Item of type PARAGRAPH_TEXT

I'm using apps script in a Google Spreadsheet to do multiple things with a Form.

EDIT: for visual people like myself: https://docs.google.com/file/d/0B0dOXR40dAVgNk1MVkZjdjFDLW8/edit?usp=sharing

  1. The Spreadsheet first creates the Form based on the values of specific cells in a target sheet. This means it fills the newly created Form with Items that are matched with those cells as specified by the user.

  2. The Spreadsheet then connects the newly created Form to itself so the responses that are sent to the Form are also sent to the Spreadsheet. By doing this, a new sheet is created in the Spreadsheet to contain those responses.

  3. The user can then request the Spreadsheet to generate a URL. This URL is targeted at the Form, but is based on what's already filled in the target sheet. The URL has to be generated because this is the only way to have pre-filled values for the Items in the Form.

  4. The newly generated URL is followed by another user. The URL takes them to the Form but it contains those pre-filled values as defined by the Spreadsheet that generate the URL.

  5. The other user can edit those values of the Form and hit submit. The responce is sent to the Form which then sends it to the Spreadsheet to populate the bottom-most row on the sheet that was created to contain those responses.

  6. A Trigger is activated (called onFormSubmit) which then grabs the values of the top-most line (just below the line that contains the labels for the columns) and promptly delete that row. The Spreadsheet then uses those values to fill out the values of the target sheet's cells - the same ones that were used to generate that URL from step 3.

    • To clarify, the point of all of this is to create a secure connection between an untrustworthy user (one who, if otherwise, was given permission to edit the Spreadsheet would essentially be able to access EVERYTHING, including the scripts!) and the user who owns the Spreadsheet. The user who owns the Spreadsheet can then programmaticly limit what the untrustworthy user can edit on the Spreadsheet this way.

    • It's just after this point that things start to go awry...

  7. After the target sheet has been edited based on the submitted response, a new URL must be generated to contain those newly updated values. The user must again request the Spreadsheet to generate a URL which would replace the old one.

    • This doesn't happen for some reason. It used to work just fine, but for some reason, now it just crashes when parsing the first Item in the Form.

EXECUTION TRANSCRIPT:

[13-08-26 10:10:33:779 EDT] Starting execution
[13-08-26 10:10:33:799 EDT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[13-08-26 10:10:33:950 EDT] Spreadsheet.getSheetByName([**REDACTED**]) [0.15 seconds]
[13-08-26 10:10:33:950 EDT] Sheet.getRange([B11:L68]) [0 seconds]
[13-08-26 10:10:33:969 EDT] Spreadsheet.getSheetByName([Element Types]) [0.018 seconds]
[13-08-26 10:10:33:988 EDT] Spreadsheet.getSheetByName([Due Date Last Checked]) [0.018 seconds]
[13-08-26 10:10:33:988 EDT] Sheet.getRange([1, 5]) [0 seconds]
[13-08-26 10:10:33:989 EDT] Range.setFormula([]) [0 seconds]
[13-08-26 10:10:33:989 EDT] Range.setFormula([=NOW()]) [0 seconds]
[13-08-26 10:10:34:173 EDT] Range.getValue() [0.183 seconds]
[13-08-26 10:10:34:420 EDT] DriveApp.getFolderById([**REDACTED**]) [0.247 seconds]
[13-08-26 10:10:34:420 EDT] SpreadsheetApp.getActiveSpreadsheet() [0 seconds]
[13-08-26 10:10:34:429 EDT] Spreadsheet.getName() [0.008 seconds]
[13-08-26 10:10:34:429 EDT] Folder.getFilesByName([**REDACTED**]) [0 seconds]
[13-08-26 10:10:35:018 EDT] (class).hasNext() [0.588 seconds]
[13-08-26 10:10:35:018 EDT] (class).next() [0 seconds]
[13-08-26 10:10:35:027 EDT] File.getId() [0 seconds]
[13-08-26 10:10:35:249 EDT] FormApp.openById([**REDACTED**]) [0.221 seconds]
[13-08-26 10:10:35:336 EDT] Form.getItems() [0.083 seconds]
[13-08-26 10:10:35:381 EDT] Form.createResponse() [0.039 seconds]
[13-08-26 10:10:35:398 EDT] Spreadsheet.getSheetByName([Cover Sheet]) [0.009 seconds]
[13-08-26 10:10:35:398 EDT] Sheet.getRange([G26]) [0 seconds]
[13-08-26 10:10:35:410 EDT] Range.getValue() [0.011 seconds]
[13-08-26 10:10:35:411 EDT] Item.toString() [0 seconds]
[13-08-26 10:10:35:572 EDT] Execution failed: TypeError: Cannot find function asParagraghTextItem in object Item. (line 82, file "Form Scripts") [1.653 seconds total runtime]

The chunk of code in question in this script that causes the crash looks like this:

var form = FormApp.openById(forms.next().getId());
var items = form.getItems();
var form_response = form.createResponse();

var item = items[0];
//Logger.log(item_i+","+"expected ParagraphTextItem: "+item.getType());
var comment = spreadsheet.getSheetByName("Cover Sheet").getRange("G26").getValue();
if(comment){
  //THIS LINE BELOW ME IS THE LINE THAT'S CAUSING THE CRASH
  var response = item.asParagraghTextItem().createResponse(comment);
  form_response.withItemResponse(response);
}

So! If I re-run this script BUT with the line with the Logger stuff (the one that's commented out), we get this in the Logs:

[13-08-26 10:35:15:225 EDT] undefined,expected ParagraphTextItem: PARAGRAPH_TEXT

This is very odd since the crash is being caused by that Item apparently NOT being of type ParagraghTextItem.

Any ideas? Hopefully someone at Google notices this, since I'm fairly certain this is a coder's bug and not a run-time error that's the result of some bad code on my part (although I may just as likely be at fault here, in which case I'll receive a healthy dose of humility after that realization has been made).

Upvotes: 0

Views: 767

Answers (1)

Taras
Taras

Reputation: 1023

please correct your typo: there is no method named asParagraghTextItem. I think you mean asParagraphTextIteminstead.

Upvotes: 1

Related Questions