Reputation: 168
I've got a working app that saves a document into a user-specified folder in their collection. This works fine except when they want to save into their root folder.
According to the docs,
function testGetRoot() {
var root = DocsList.getRootFolder();
var folderName = DocsList.getFolderById(rootid);
Logger.log("Folder name: " + folderName.getName());
}
folderName shows 'Root' as the getName for the root of my collection.
So, seeing that I added 'Root' to the ListBox that is populated by the names of the other folders in my collection. That of course, was too easy..
**var collectionFolder = DocsList.getFolder(selectedCollection)**;
I get a 'cannot find folder Root' error message.
So I can get the Name of the root, but can't seem to get it to be accepted by getFolder method.
What am I missing?
Upvotes: 0
Views: 1491
Reputation: 168
I wound up hardcoding 'Root' in the logic where I addtoFolder, so that if the user selects Root, the addToFolder method isn't called. The default behavior is that the document will be saved to the Root collection, unless otherwise specified.
Upvotes: 0
Reputation: 17752
You're not missing anything. You should report this issue in the issue tracker, as it makes sense. But as a alternative, which I'd probably use even if this worked, is referencing always to the folder id. e.g.
listbox.addItem(folder.getName(), folder.getId());
//then, later on in your handler...
//you'll receive the selected folder id directly, instead of its name.
//allowing you to use the more reliable getFolderById
var selectedFolder = DocsList.getFolderById(e.paramater.listbox);
//which works also for the root folder
Upvotes: 3