0
votes

So

I'm getting this error

Oops You do not have permission to call query (line 7)

When I try to query a ScriptDB database in an onEdit() function within Google Spreadsheet Apps script. Below is the code I use to get the repeatable error:

function onEdit(){
  //tell me event has happened
  Browser.msgBox("onEdit() Fired")
  //get ScriptDB reference
  var db = ScriptDb.getMyDb();
  //perform any query
  var results = db.query({})
}

Replace onEdit() with notonEdit() and it works as expected when triggered manually.

function notonEdit(){
  //tell me event has happened
  Browser.msgBox("notonEdit() Fired")
  //get ScriptDB reference
  var db = ScriptDb.getMyDb();
  //perform any query
  var results = db.query({})
}

Is there some sort of permission I am not correctly setting or are ScriptDB queries not allowed to function in event functions by design? Is anybody else seeing this problem?

Tom

2

2 Answers

0
votes

There are two ways to attach a script to the onEdit trigger: (1) choose the name onEdit for your function or (2) in the Script Editor, go to Resources>Current Script's Triggers and add notonEdit/From spreadsheet/On edit. (2) should be ok for you. See the guide for the difference between (1) and (2).

0
votes

Is there some sort of permission I am not correctly setting or are ScriptDB queries not allowed to function in event functions by design?

I believe it's the latter. So-called simple triggers are somewhat limited in what they can access, as they are run as the active user. Without this limitation, there would be a fairly major security hole.