1

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?

4
  • Make sure solveThis is defined before it is used in the google script. Commented Jan 8, 2020 at 13:05
  • evolutionxbox // but how defined before? These are two separate files. Commented Jan 8, 2020 at 13:14
  • They are used in the same HTML file, correct? Commented Jan 8, 2020 at 13:15
  • evolutionxbox // No, I want to use the JavaScript library in the .gs file. In conclusion, the function is html JavaScript. I want to use that function in the .gs file. Commented Jan 8, 2020 at 13:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.