0

FormApp isn't behaving as expected. Trying to open a form either by URL or ID like this:

var form = FormApp.openById(id);

The code execution results in this (quiet) error in the logs:

Exception: You do not have permission to call FormApp.openByUrl.
Required permissions: https://www.googleapis.com/auth/forms

But File-->Project Properties-->Scopes shows

3 OAuth Scopes required by the script:

https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/forms
https://www.googleapis.com/auth/spreadsheets

I even tried setting the oauthscopes manually as suggested elsewhere without any success.

So now I'm confused ... what am I missing here?

Addendum:

If I run the function manually from the Google Scripts editor, the function executes as expected.

The function throws the above error only when it is called by the Spreadsheet.

permafrost91
  • 63
  • 1
  • 5
  • Where are you making this call from, how are you making it and do you have edit permissions of the form you are trying to open? – James D Mar 30 '20 at 13:36
  • The function is executed after a sheet is edited (it's part of a series of functions called by onEdit). However, if I execute it manually from the script editor, it executes as expected. And yes, I have permissions. – permafrost91 Mar 30 '20 at 13:37
  • 1
    Ok, so have you installed the onEdit trigger and then tried to debug after installing the trigger to force an authorization request? Note that a simple onEdit won't be able to open a form. – James D Mar 30 '20 at 13:48
  • The remainder of the function works fine. It's just this part of the code that doesn't execute. – permafrost91 Mar 30 '20 at 15:14
  • Ok, I've tried running this code in onOpen() to install a trigger to the function which runs the above code: `ScriptApp.newTrigger('validateData').forSpreadsheet(ss).onOpen().create();` First time using installable triggers but it doesn't seem to be working (unless I'm not doing it correctly. Trying to read up on Add On triggers via the Manifest but haven't found the right answer that way either. – permafrost91 Mar 30 '20 at 15:37
  • Actually ... if I execute it via `Run-->Test as add-on` it works! – permafrost91 Mar 30 '20 at 15:41
  • I think you are a little confused about the difference between simple and installed triggers. This answer is a little old but still explains the difference [Google script project trigger not running](https://stackoverflow.com/questions/45155847/google-script-project-trigger-not-running/45157034#45157034). You seem to be going about everything in a very difficult way. – James D Mar 30 '20 at 16:34

0 Answers0