Either use a global variable, or put the values into cache.
To declare a global variable, declare the variable outside of a function:
var id = "";
var minutes = "";
function doGet(e) {
id = e.parameter.id;
minutes = e.parameter.min;
var html = . . . . . HTML HERE;
onRun(id, minutes);
return HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
Or put the values into Cache:
function doGet(e) {
var id = e.parameter.id;
var minutes = e.parameter.min;
if (!!id) {cache.put('theid', id, 4000);};
if (!!minutes) {cache.put('min', minutes, 4000);};
var html = . . . . . HTML HERE;
onRun(id, minutes);
return HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
Then you can retrieve the values from cache, or use the global variable anywhere in your code.
So, you don't need to pass anything from the HTML to the .gs
code.
I don't see anything calling the onRun()
function within the doGet()
function.
You can call another function from the doGet()
function, as long as it's before the return
. return
stops the function at that point.
function doGet(e) {
var id = e.parameter.id;
var minutes = e.parameter.min;
var html = . . . . . HTML HERE;
onRun(id, minutes);
return HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
You can't have:
return HtmlService.createHtmlOutput(html).setSandboxMode(HtmlService.SandboxMode.IFRAME);
onRun(id, minutes);
You can also trigger script to run from an HTML Script tag with window.onload = function() {code};
:
<script>
window.onload = function() {
console.log("This onload did run");
code here;
};
</script>
To pass multiple variables, just separate them by a comma:
function doGet(e) {
code here;
onRun(id, minutes);
}
function onRun(argId, argMinutes) {
Logger.log('argId: ' + argId);
Logger.log('argMinutes: ' + argMinutes);
};