Reputation: 83
The below code is creating the clients specified folder in the clientFolderParent and the 3 sub folders Client Folders -New Client --Sales --Weekly --Statements
but it is also creating all 4 new folders in the root of the drive. Why is this? What am I doing wrong?
var clientFolderParent =DriveApp.getFolderById("xxxxx");
var firstLevel = clientFolderParent.createFolder(DriveApp.createFolder(driveFolder));
var secondLevel = DriveApp.getFoldersByName(driveFolder);
var secondLevelID = secondLevel.next();
var salesID = secondLevelID.createFolder(DriveApp.createFolder("Sales Order").getId());
var weeklyID = secondLevelID.createFolder(DriveApp.createFolder("Weekly Invoice").getId());
var statID = secondLevelID.createFolder(DriveApp.createFolder("Statement").getId());
Upvotes: 0
Views: 56
Reputation: 3152
When you call the method DriveApp
you get the root of your drive.
Therefore calling the method var firstLevel = clientFolderParent.createFolder(DriveApp.createFolder(driveFolder));
is creating 2 different folders 1 in the clientFolderParent and the other in the root (you can check that they are different by looking at the folderIDs).
You haven't provided your full code but I assume that var driveFolder =
contains the string name that you want to name the new folder so,
change var firstLevel = clientFolderParent.createFolder(DriveApp.createFolder(driveFolder))
to var firstLevel = clientFolderParent.createFolder(driveFolder);
and this should fix your problem. Do the same in other lines below.
This is the best I can do by guessing the code above the lines you have provided.
Upvotes: 1