I want to move the current file to a folder and remove it from the one that it is in, based on a cell value change. Here is what I have:
function onEdit() {
var File = SpreadsheetApp.getActiveSpreadsheet();
var TransferComplete = File.getSheetByName("Sheet9").getRange("E24").getValue();
var ActiveFolder = DriveApp.getFolderById("a0lweiurnawoeiuranwv");
var ArchiveFolder = DriveApp.getFolderById("apsleriuoavwnoeiura");
if (TransferComplete = "Yes" )
{ArchiveFolder.addFile(File) && ActiveFolder.removeFile(File)};
}
The error says that it cant find "add file" method.
To move a file, you must first get the file itself as a file and not as a spreadsheet.
You need to use
DriveApp.getFileById()
to retrieve a file object that you can then pass intoArchiveFolder.addFile()
.Additionally you have some syntax errors with your code.
=
instead of a comparative operator==
or'==='
to compareTransferComplete
to"Yes"
;
at the end of an if statementYou are using
&&
to separate two statements, you need to separate them like soif(TransferComplete == "Yes" ){ ArchiveFolder.addFile(File); ActiveFolder.removeFile(File); }
Corrected code: