0

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 }; 
1
  • You could use a webapp as sort of an api by issuing querystring commands via UrlFetchApp. I generally return ContentService if anything. Commented Jan 27, 2021 at 0:44

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.