0

I want the folders with all the files or subfolders in them to be moved from one directory/folder to another based on the value in google sheet, but at the same time not change the Id of the folder because the folder is shared with other team members, therefore, don't want to mess with access. I have searched through all the net. what I found was the script that creates the copy of the folder (that definitely changes the ID) and removes the old folder, which may definitely change the access status. The folder url lies in the sheet that should be moved through directories. Here is the code that may help for better understanding.

function onEdit(e) { 
 const inactive_folder = DriveApp.getFileById('1_hBkktH0Alzx06XS0Hu2tI0MSQ_SffKw');
 const active_folder = DriveApp.getFolderById('13uon5guBduiA0gCKiLjl9ElOgek9CiU6');

 if (e.range.columnStart != 1 || e.value != "Inactive"){
  const rData = e.source.getActiveSheet().getRange(e.range.rowStart,1,1,13).getValues();
  // Url of the client folder in 11th column 
  let client_folder = rData[0][11];

  DriveApp.getFileById(client_folder).moveTo(inactive_folder);
 } else {
  DriveApp.getFileById(client_folder).moveTo(active_folder);
 }
}

Any help will be highly appreciated.

  • In your situation, where are `inactive_folder` and `active_folder`? For example, those are put in the shared drive or in your Google Drive? – Tanaike Dec 03 '21 at 11:29
  • Not with `onEdit()` trigger, definitely. – Yuri Khristich Dec 03 '21 at 16:12
  • They are in google drive in the shared drive. Basically, I want this function to read the changes every time and take actions accordingly i.e., It should look into the folder link in column 11 and the status of the client in column 1, if the status is inactive it should move the client folder to Inactive and if the client is active again it should move the same client folder again to Active. – Mubashir Rehman Dec 04 '21 at 12:32
  • What makes oyu think that the code snippet you provided `creates the copy of the folder`? This is not the case, this code moves the folder. However, as pointed out by @Yuri Khristich this code will not work on SIMPLE onEdit trigger becasue of [authorization issues](https://developers.google.com/apps-script/guides/triggers#restrictions). – ziganotschka Dec 06 '21 at 08:46
  • I have another snippet added in the script that creates the folders and sheets for every client that I add to the sheet. Now I want some type of script that moves these folders/sheets to active or inactive directory/folder as the client status is changed. These folders/sheets are wrapped into one folder with a client name that may be unique. like There is a client name folder, in it, there are other subfolders and sheets. So if possible we can also move just one folder with the client's name and that may move all subfolders and files with it. – Mubashir Rehman Dec 06 '21 at 09:28
  • Yes you are right there can be some authorization issues, therefore I am seeking your (the experts' help). The provided snippet may all be wrong, I have provided that just to make some better understanding of what I actually want the script to do. Any help will be highly appreciated. Thank you. – Mubashir Rehman Dec 06 '21 at 09:32

0 Answers0