google-sheetsgoogle-apps-script

Unable to run server functions from dialogs or sidebars in Google Sheets


My code was initially different, but I tried a small example from this answer and I have the same problem. The relevant code is copied below.

Code.gs

function doSomething(obj) {
  SpreadsheetApp.getUi().alert(obj.date)
}
    
function launchMyDialog() { 
 SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('ah2'),"Dialog")
}

ah2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <base target="_top">
</head>
<body>
  <form>
    <input type="text" name="date" id="dp" placeholder="YYYY-MM-DD"/>
    <input type="button" value="Submit" onClick="runThis(this.parentNode);">
  </form>
  <script>
    function runThis(obj) {
      google.script.run.doSomething(obj);
    }
    </script>
</body>
</html>

What should happen is that when the form in the dialog is submitted, an alert is shown in the sheet. However, nothing happens when I click Submit. Opening up the dev tools, I see the request being made with a 200 response. However, the response is the following:

)]}'

[["op.exec",null,[2,null,"We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED.","ScriptError"]],["di",773]]

I'm not sure how what permission is missing or how to grant it. I haven't customized appscript.json to specify any scopes, so I'm using whatever the default is. I've tried this in multiple browsers in case it was some sort of browser issue.

This works fine on my personal Google account, but not for my Google Workspace account. I am an admin in this account, so I can change whatever settings necessary.


Solution

  • That sounds like an error you can get when you are signed into multiple google accounts at the same time. Have you tried logging out of all of them and then back into the one with the script and trying to rerun it?