Reputation: 97
Ok, this is officially driving me nuts. I am getting the error "TypeError: Cannot find function addfile in object JobSheetJune2015." with this code. I have the same code elsewhere that is very similar to this except it is creating the folder and then adding the file, no problems. I cannot seem to figure out why the folder is not a Folder object that can accept addFile(). The log shows folders as a FolderIterator, as expected. The log shows the name of the folder JobSheetJune2015, not sure if this should be the case, thought it should show Folder, but in the other part of the code it shows the folder name as well, so maybe its fine.
I'm obviously missing something, and I have run out of ideas. Grateful for any help and insight.
if (DriveApp.getFoldersByName('JobSheet' + year).hasNext() == true) {
if (DriveApp.getFoldersByName('JobSheet' + months + year).hasNext() == true) {
var folders = DriveApp.getFoldersByName('JobSheet' + months + year);
var folder = folders.next();
var file = DriveApp.getFilesByName(newSpreadsheetName).next();
folder.addfile(file);
}
}
Upvotes: 2
Views: 65
Reputation: 322
You may kick yourself for this, but it looks like you have a typo. You need to capitalize the "F" in folder.addfile(file). It should be folder.addFile(file);
Whenever you see the error "TypeError: Cannot find function _____ in object _____." what it means is that you are trying to call a method that does not exist in the object you are referencing. This usually means either a typo or that the object you are trying to manipulate is a different type than you expected. Keep that tidbit in your back pocket for the next time you need to debug.
Upvotes: 1