kgsw
kgsw

Reputation: 85

Running a web app from a google sheet menu click

I am trying to run a webapp from a spreadsheet when the user clicks a menu item. The code is below. My problem is I get this error message

We're sorry, a server error occurred. Please wait a bit and try again

I have deployed it as a webapp and when I do the test deployment all is good but if I try and run it from the spreadsheet I get the above. What am I doing wrong?

function onOpen() {
  var ss = SpreadsheetApp.getActive();
  var menuEntries = [{name: "xxx", functionName: "doGet"}];
  ss.addMenu("yyy", menuEntries);
}

function doGet()
{
   var ss = SpreadsheetApp.getActive();
  
      let HTMLString = "<style> h1,p {font-family: 'Helvitica', 'Arial'}</style>"
                    + "<h1>Hello World!</h1>"
                    + "<p>Welcome to the Web App";
    HTMLOutput = HtmlService.createHtmlOutput(HTMLString);
    return HTMLOutput
};

Upvotes: 0

Views: 670

Answers (1)

Wicket
Wicket

Reputation: 38190

It's not possible to directly run a web app from a custom menu but yo might open a dialog with client-side code that will open your web app on a new window. See Google Apps Script to open a URL for details.

Explanation

doGet is a reserved function name that will be triggered when the web app url gets an HTTP GET call. While it can be called from a custom menu, it's not expecting a "return" from the function called, so there is no place available to render the return of your doGet function.

Upvotes: 2

Related Questions