Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
La ID de carpeta se muestra en Logger pero el valor no me permite mover el archivo a dicha ID de carpeta

Bien, tengo una hoja que uso para llevar un registro de las propinas en el trabajo. Dado que es una hoja compartida para mantenerlo simple, solo copio la hoja cuando está lista y luego la archivo copiada en una subcarpeta según el año. Todo el código funciona perfecto excepto cuando trato de mover la hoja copiada a la carpeta que quiero. Como quiero mantener esto lo más automatizado posible, tengo un código para leer la fecha dentro de la hoja y crear una nueva carpeta para el año o mover el archivo a la carpeta del año que ya existe. Por alguna razón, el archivo no se moverá a la carpeta que quiero y lo he intentado de varias maneras: dentro de la función 'makeCopy', así como DriveApp.getFileById().moveTo(); Aquí está mi código, el error se ejecuta en la parte inferior del código:

 //Create folder if does not exists only function createFolder(folderID, folderName){ var parentFolder = DriveApp.getFolderById(folderID); var subFolders = parentFolder.getFolders(); var doesntExists = true; var newFolder = ''; // Check if folder already exists. while(subFolders.hasNext()){ var folder = subFolders.next(); //If the name exists return the id of the folder if(folder.getName() === folderName){ doesntExists = false; newFolder = folder; return newFolder.getId(); }; }; //If the name doesn't exists, then create a new folder if(doesntExists == true){ //If the file doesn't exists newFolder = parentFolder.createFolder(folderName); return newFolder.getId(); }; }; function start(){ //Parent folder (Location) var FOLDER_ID = '1yinFsKfMP3_pWbM7BnOKcNRk-BDcty6E'; //Add the name of the folder here (Year of the sheet): var year = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Instructions").getRange('L2').getDisplayValue(); var NEW_FOLDER_NAME = year; //Create a new folder if a folder for the year doesnt exist (reverts to function:createFolder) var myFolderID = createFolder(FOLDER_ID, NEW_FOLDER_NAME); //Get the file ID of the parent file (Tip Tracker) var getID = SpreadsheetApp.getActive().getId(); //Get the current name of the Tip Tracker (with dates) var getName = SpreadsheetApp.getActive().getName(); //Create copy of Tip Tracker to be filed accordingly var newFileID = DriveApp.getFileById(getID).makeCopy(getName + " ").getId(); var getNewFile = DriveApp.getFileById(newFileID); getNewFile.moveTo(myFolderID); Logger.log(newFileID); Logger.log(myFolderID); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Intente crear un getMyFolder como lo hizo con getNewFile y moveTo la carpeta frente a la ID.

 const myFolder = DriveApp.getFolderById(myFolderID) // ... getNewFile.moveTo(myFolder)

File.moveTo(folder) toma una Carpeta, no una ID.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!