TypeError: Cannot find function hasNext in object

2019-08-15 03:32发布

I'm trying to save an email in to a particular drive folder however getting error message

TypeError: Cannot find function hasNext in object

Any idea how I can overcome this.

function saveGmailToDrive() { 
    var gmailLabels  = "SaveToDrivetest";  
    var driveFolder  = "Emails saved by " + Session.getActiveUser().getEmail()

    /* Gmail Label that contains the queue */
    var label = GmailApp.getUserLabelByName(gmailLabels) ? 
                    GmailApp.getUserLabelByName(gmailLabels) :
                    GmailApp.createLabel(gmailLabels);

    var threads = GmailApp.search("in:" + gmailLabels, 0, 5);  

    if (threads.length > 0) {    
        /* Google Drive folder where the Files would be saved */
        var folders = DriveApp.getFolderById("0B9Ug3fXvrl5HeGRddddMcE93bkE3Q1k");
        var folder = folders.hasNext() ?
                         folders.next() : 
                         DriveApp.createFolder(driveFolder);
    }

1条回答
Luminary・发光体
2楼-- · 2019-08-15 04:24

In general: if the noun after "get" is in plural form, you get an iterator to be used with hasNext and next methods. If that noun is in singular form, you get a single object. Examples:

  • getFileById returns one File
  • getFiles returns an iterator
  • getFilesByName returns an iterator
  • getFilesByType returns an iterator
  • getFolderById returns one Folder
  • getFolders returns an iterator
  • getFoldersByName returns an iterator
查看更多
登录 后发表回答