Reputation: 23
On the trigger of a form submission, I have created a copy of a sheet. I can't figure out how to save that copied sheet in a specific folder. Once the copy is created, I've tried calling the folder then saving the copied sheet to that folder.
//Copying the sheet (triggered by a form submission)
var copyOfSheet = SpreadsheetApp.openById(Id.of.sheet.I.am.copying).copy(name of sheet);
//Grabbing the folder I want to save to
var specificFolder = Drive.App.getFolderById(folderID.in.quotes);
//saving the copy to that folder (This is the part that I think is wrong but I'm not sure how to fix)
specificFolder.addFile(copyOfSheet);
The goal is that the file would save in this specific folder instead of my general drive. Instead I am getting a not a function error.
Upvotes: 2
Views: 1212
Reputation: 201613
If my understanding is correct, how about this answer?
In this pattern, your script was modified.
//Copying the sheet (triggered by a form submission)
var copyOfSheet = SpreadsheetApp.openById(Id.of.sheet.I.am.copying).copy(name of sheet).getId();
//Grabbing the folder I want to save to
var specificFolder = DriveApp.getFolderById(folderID.in.quotes);
//saving the copy to that folder
// Retrieve the copied file.
var file = DriveApp.getFileById(copyOfSheet);
// Add the file to "specificFolder".
specificFolder.addFile(file);
// Remove the parent folder of copied file.
file.getParents().next().removeFile(file);
In this pattern, the Spreadsheet is directly copied to the specific folder using makeCopy()
.
var specificFolder = DriveApp.getFolderById(folderID.in.quotes);
DriveApp.getFileById(Id.of.sheet.I.am.copying).makeCopy(name of sheet, specificFolder);
Id.of.sheet.I.am.copying
, name of sheet
and folderID.in.quotes
are correct.If I misunderstood your question and this was not the result you want, I apologize.
Upvotes: 1