Kelli Roddy
Kelli Roddy

Reputation: 503

DriveApp.createFolder creates folder for wrong user

The following code is in the onFormSubmit trigger for a Google spreadsheet tied to a Google Form:

      var folders = DriveApp.getFoldersByName("Test 2016 - 2017");
      if (!folders.hasNext()) {
        var folder = DriveApp.createFolder("Test 2016 - 2017");
      } else {
        var folder = folders.next();
      }

      var
 docID = DriveApp.getFileById('id').makeCopy('Test Document ', folder).getId();
}

When someone uses the link for the form and submits it, this script will create a folder for the owner of the form/spreadsheet - me.

Shouldn't DriveApp be set for the current user? Am I calling the wrong function? Is this a Google bug? Can anyone help?

Thanks for your time!

Upvotes: 1

Views: 321

Answers (2)

Zig Mandel
Zig Mandel

Reputation: 19834

this is by design. onFormSubmit triggers run with owner permissions. imagine simply filling a form would give me access to whatever scopes your script has, without you ever authorizing.

Build a webapp instead, and publish it to run as user.

Upvotes: 4

Tanaike
Tanaike

Reputation: 201513

You can use Access and Permission in DriveApp class.

docID.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);

References:

Upvotes: 0

Related Questions