1

I am trying to create a webapp using Google Apps Script.

However, when I deploy my project(in a new version) as webapp and then view Log, it shows "No functions have been run in this editor session" message.

The HTML Code is saved as "page.html" (as expected by the function). Please help me

function doGet(e)
{
  
  return HtmlService.createHtmlOutputFromFile("page");
  Logger.log(e);
}
<!DOCTYPE html>
<html>
<head>
  <base target="_top">
</head>
<body>
  <h1> Hello 3 </h1>
</body>
</html>
  • use `console.log()` and view>stackdriver logging. if that doesn't work, switch gcp to a standard gcp.See [tag info page](https://stackoverflow.com/tags/google-apps-script/info) for more details. – TheMaster Apr 09 '20 at 21:20
  • 1
    Basically there is nothing to log, your doGet returns before making any log. Logger.log and console.log will work in the appscript if you are using V8 run time. https://developers.google.com/apps-script/guides/v8-runtime#ui_changes_for_logging – Anees Hameed Apr 09 '20 at 21:36

2 Answers2

3

You have 2 small issues,

1.- Your doGet(e) is executing the return statement before you actually log the e event. and so Logger.log(e); is not executed.

2.- The Apps script Logger class only works in the apps script session. (You would have to execute the function from within the editor to see this log). Also keep in mind that doGet(e) when run from within the editor will have a null e, but when making a GET request to your deployed webapp it will not be null.

Solution:

function doGet(e){
    // Log the event in StackDriver
    console.log(e); 
    return HtmlService.createHtmlOutputFromFile("page");
}
Aerials
  • 4,231
  • 1
  • 16
  • 20
0

Here's a quick dialog:

GS:

function showDialog() {
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile("page"), 'test');
}

function sayHowdy() {
  return "Howdy";
}

HTML:

<!DOCTYPE html>
<html>
<head>
  <base target="_top">
</head>
<body>
  <h1> Hello 3 </h1>
  <input id="msg" type="text" readonly />
  <input type="button" value="Say Hello" onClick="sayHello()" />
  <script>
  function sayHello() {
    google.script.run
    .withSuccessHandler(function(msg){
      document.getElementById('msg').value=msg;
      })
      .sayHowdy()
  }
  </script>
</body>
</html>
Cooper
  • 59,616
  • 6
  • 23
  • 54