Reputation: 15
im not english user but im trying to right write. plz get this
i want
A== Google App script .gs
var result = solvethis(1,3);
Logger.Log(result) // 4
B== webapp javascript .html
<script>
function solvethis(a,b){
return a+b
}
</script>
why i do this want.
i want use some data Library with make javascript => alasql.js
but in .gs -> alasql.js is not work.
so i have to use html.
i dont know a lot but i know dget.
1===.gs
function dget(e){
return HtmlService.createTemplateFromFile("index").evaluate();
}
alasql(select * )
2===.html
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
---------------- => it not work.
i do not want webapp page directly open. but i want js Library in .gs
how can i do this?
Upvotes: 1
Views: 78
Reputation: 9872
You cannot invoke client side functions from the server, with the sole exception of the success or failure handler specified for a client-side-initiated call to a server function. Note that your server-side code cannot know which client side function was registered as the response handler, or even if there was one registered at all.
So no, you can't "just" call a .html-defined function from your .gs files.
Please review the HTMLService guide and API reference
// client.html (you write the UI and other stuff for the sidebar or modal or webapp page)
function calledByServer(serverOutput) {
console.log({ serverOutput }); // or whatever you want to do with the response
}
function doServer(...argsArray) { //invoke somehow, e.g. a client-side click handler
google.script.run
.withSuccessHandler(calledByServer)
.ServerSideFunctionName(argsArray);
}
// Code.gs
function ServerSideFunctionName(foo) {
console.log(foo); // Stackdriver logging, since Logger is instance specific
// Do something with foo
return someValueToSendToClient;
}
If you want to have that library available, you must build and use a UI to work with it, in purely client-side code.
Upvotes: 1