Home > database >  Modify google app script for whole column A
Modify google app script for whole column A

Time:07-15

I have a File that contains a list of Google Drive File's IDs in column A. In column B I have emails. And column C a list of roles (you know when you share a google sheet with someone)

So I have many rows that contain different file IDs, emails and roles. And I need to assign the email and role in that row to file's ID of that row. I have found a great script (credit to enter image description here

Just tested it with different emails and it works. Let me know if this works for you.

CodePudding user response:

I'd propose this modification:

function shareFiles() {
  const sheet = SpreadsheetApp.getActiveSheet();
  const [header, ...data] = sheet.getDataRange().getValues();

  for (let [id,email,role] of data) {
    try {
      let file = DriveApp.getFileById(id);
      switch (role) {
        case ("Viewer"):    file.addViewer(email); break;
        case ("Commenter"): file.addCommenter(email); break;
        case ("Editor"):    file.addEditor(email); break;
      }
    }
    catch(err) { console.log(err) }
  }
}
  • Related