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);
}
In general: if the noun after "get" is in plural form, you get an iterator to be used with
hasNext
andnext
methods. If that noun is in singular form, you get a single object. Examples:getFileById
returns one FilegetFiles
returns an iteratorgetFilesByName
returns an iteratorgetFilesByType
returns an iteratorgetFolderById
returns one FoldergetFolders
returns an iteratorgetFoldersByName
returns an iterator