0

Currently

I have a sidebar in Google Sheets (launched on open using a project trigger) with a button that is meant to call a script from a .gs file enter image description here

The code:

.gs

function addSideBar() {
  var html = HtmlService.createHtmlOutputFromFile('Index')
      .setTitle('My Sidebar')
      .setWidth(500);
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
      .showSidebar(html);
}

function logMe() {
 console.log("I am a log!"); 
}

.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
     <button value="Connect" name="Connect" onclick="connect()">Connect</button>
  <br>
    <script>
    
    function connect() {
        google.script.run
        .withSuccessHandler(function() {console.log("More Success!")})
        .withFailureHandler(function(err) {
            console.log("Error Message:")
            console.log(err.message)
        })
        .logMe();
        console.log("Success!");
    }
    </script>
    </body>
</html>

Issue

I can't even get the HTML code to call a simple log function server side! I am expecting a log (somewhere) to read I am a log! but this doesn't show up on the logs either client or server side.

The logs show that the failure handler is being called with the message: "We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED."

enter image description here

It's weird because I have been able to get an HTML Service side script to call the server before in a separate project with a pop-up window, and am wondering if it's due to:

  • the use of the side bar, or
  • the way I setup my trigger to create the side bar.

Any help would be appreciated.

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Wronski
  • 1,506
  • 3
  • 18
  • 37
  • 1
    Add success and failure handlers first. – TheMaster Jul 27 '20 at 19:36
  • @TheMaster, adding those handlers is not necessary to call a server side script, and I have already tried that. But to ensure I am being thorough, here is the same code with success and failure handlers: ` google.script.run .withSuccessHandler(function() {console.log("More Success!")}) .withFailureHandler(function(err) {console.log(err)}) .logMe(); console.log("Success!");` and the result is the same. Note, the success and failure logs are also not being called, which might be a clue to the issue. – Wronski Jul 27 '20 at 19:43
  • @TheMaster, with some refreshing of the page, I managed to get the logs to show the "failure" message, and have updated the description accordingly. – Wronski Jul 27 '20 at 20:01
  • 1
    Log the `err.message` – TheMaster Jul 27 '20 at 20:10
  • @TheMaster. Thank you. That is helpful, although need to work out next steps. – Wronski Jul 27 '20 at 20:18
  • 1
    Quote the message as text in your question. There were similar errors like these when you used two or more Google accounts. – TheMaster Jul 27 '20 at 20:23
  • @TheMaster, it seems to be the same issue. Thank you. – Wronski Jul 27 '20 at 20:38

1 Answers1

0

Still haven't been able to fix the issue, but a workaround was to only be logged into a single Google Account, as the issue seems to be related to being logged into 2 or more Google Accounts at once.

Ref: We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED

Wronski
  • 1,506
  • 3
  • 18
  • 37