Using addEditor(s) with users outside your workspace

Viewed 38

I used appscript to create copies of a document and share them with a particular user, this works fine in that the code creates the document and the user receives an invitation to edit, but I have found that at least some users are not able to edit the document. When I view the sharing options on the individual docs, I can see that they are restricted to my workspace only. I had the same issue when doing this process manually, but thought addEditor would be able to override this, as the shared Gdrive is not restricted in this way overall (i.e, we can share docs with individuals by adding them as editor, from outside our organisation.) . I do not want to have to individually share >100 docs per week manually, so any fixes/workarounds would be very appreciated. Some limitations: the doc must be shared to one user exactly, but still be accessible to everyone in my workspace. All of the users I am sharing the document are external to the organisation.

I tried making the master copy of the file accessible to anyone who had the link, hoping that this would mean they could access the file without manually approving the request, but it looks like this doesn't transfer to the copies. I'm not sure enough of the actual issue to know that this would solve it.

This is how the code looks:

function createCopy() {
  let file = DriveApp.getFileById("ID of file to copy");
  let sheet = SpreadsheetApp.openByUrl('Sheet with names and emails').getSheetByName("Sheet1");
  let range = sheet.getRange('D2:D5');
  let email = sheet.getRange('C2:C5').getValues().flat();
  let values = range.getValues();
  let folder = DriveApp.getFolderById("Destination Folder");
  for (let i = 0; i < values.length; i++) {
    Logger.log(values[i]);
    file.makeCopy(values[i].toString(), folder).addEditor(email[i]);
  }
}
1 Answers
Related