google.script.run not returning string

丶灬走出姿态 提交于 2019-12-12 21:14:44

问题


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

Code.gs

function helloWorld() {
    return "Hello World";
}  

under code.gs which I call in:

Sidebar.html

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?


回答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:

    google.script.run
        .withSuccessHandler(functionToRun)
        .helloWorld();

    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.



来源:https://stackoverflow.com/questions/41527845/google-script-run-not-returning-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!