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);
}