Mark
Mark

Reputation: 3

Google Apps Script - How can one give out editor access to files based on a spreadsheet?

So I have a spreadsheet that has three columns. In column A I have the name of the files, in column B I have the URLs of the files, and in column C I have the email addresses of the users that need editing access.

So the user in C2 should be given access to file in B2, those in C3 to B3, etc. Can this be accomplished using addeditors() ?

How would I go about this?

Upvotes: 0

Views: 200

Answers (1)

dared
dared

Reputation: 48

function addEditors() {
  // Get the values from the active sheet
  SpreadsheetApp
    .getActiveSheet()
    // Adjust the range to suit table nb.file name col A not required
    .getRange('B1:C5')
    // Get the values
    .getValues()
    // destructure the array
    .forEach(([url, emailAddresses])=> {
      // Grant editor access 
      // nb addEditor expects a string; addEditors expects an array
      SpreadsheetApp.openByUrl(url).addEditors(emailAddresses.split(','))
    })
}

Upvotes: 1

Related Questions