maxgotstuck
maxgotstuck

Reputation: 159

Logs are not shown when the webapp is triggered by doGet

I'm currently trying to write a form in HTML that passes its input to a spreadsheet. I did it as shown in the following video: https://www.youtube.com/watch?v=RRQvySxaCW0&list=PLv9Pf9aNgemt82hBENyneRyHnD-zORB3l. The problem is that the Logger in addInfo() function isn't working when the button is clicked (In the Logs is no "Hey" when the button got clicked).

My Code.gs (Google Apps Script) file:

function doGet(){
  return HtmlService.createHtmlOutputFromFile("index");

}

function addInfo(){
  Logger.log("Hey");
}

My index.html file:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <button id="btn">Klick mich</button>

    <script>

    document.getElementById("btn").addEventListener("click",doStuff);

    function doStuff(){
      google.script.run.addInfo();
    }

    </script>
  </body>
</html>

Is anyone knowing why it is not working like that? I appreciate your help.

Best regards, Max

Upvotes: 4

Views: 1635

Answers (2)

Mateo Randwolf
Mateo Randwolf

Reputation: 2922

Issue

The logs of triggers like doGet() cannot be seen from the Apps Script IDE Logger.

Solution

Follow these steps to achieve what you are aiming for:

  1. Instead of Logger.log use console.log.
  2. In your script editor go to Resources -> Cloud Platform Project.
  3. Select the project you want to associate the script with. For that you will need to have previously created a project in the Google Cloud Platform and use its project’s number.
  4. Once you have your script linked with the project, go to View -> Stackdrive Logging and there you will be able to see the console logs of the script including the ones in the trigger functions.

For more information regarding this process, check this post where they explain more extensively the use of the Stackdrive Logger for Apps Script.

I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

Upvotes: 2

Cooper
Cooper

Reputation: 64100

I ran it as a dialog like this:

enter image description here

Upvotes: 0

Related Questions