[Solved] google.script.run not returning string

Trying to figure out Google Apps Script for making Google docs addons.
I have:


function helloWorld() {
    return "Hello World";

under code.gs which I call in:


console.log("This should say Hello World: " + google.script.run.helloWorld()) 

It returns:

This should say Hello World: undefined  

What is the obvious thing I am missing?

Enquirer: ughdotjs


Solution #1:

google.script.run won’t return a value like you’d expect a usual Apps Script function to. Instead, you should use .withSuccessHandler(functionToRun)

Like this:


    function functionToRun(argument) {
        console.log("This should say Hello World: " + argument);

In this example, the server-side Apps Script function helloWorld will run the client-side function functionToRun() and pass the result of helloWorld() as an argument.

Respondent: Justin Mai

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.