How to continue script after return from html

Skip to first unread message

Alistair George

Apr 10, 2020, 4:16:35 PM4/10/20
to Google Apps Script Community
Greetings. I have html as filename searchbox.html
the usual way to call is by return HtmlService.createHtmlOutputFromFile('searchbox').setSandboxMode(HtmlService.SandboxMode.IFRAME);
but of course return closes the script; I need to continue the script after the variable "q" is returned.
Can anyone enlighten me how to get the html script to run and return the value without having to use return (which instantiates, then closes the routine).
<!DOCTYPE html>
<input type="search" id="q" name="submit" placeholder="Search for song name..." required>
<button onclick="bclick(q.value)">Search</button />
<script type="text/javascript">
function bclick(q) {
return q; //document.write("Search Field = " + q + "<br><br>");

Which is called from here:
function doGet(e) {
e = HtmlService.createHtmlOutputFromFile('searchbox').setSandboxMode(HtmlService.SandboxMode.IFRAME); //this does not return the html
return HtmlService.createHtmlOutputFromFile('searchbox').setSandboxMode(HtmlService.SandboxMode.IFRAME);// works, but on return script ends
//code continues
var gotResults = getDriveFiles(DriveApp.getFolderById('1e9aI6k3vn3n4oI1wFewdK3NarsaCnapH'),e);

Alan Wells

Apr 10, 2020, 4:49:56 PM4/10/20
to Google Apps Script Community
What do you want the end result to be?  What are you going to eventually do with the var gotResults?

Alistair George

Apr 10, 2020, 6:02:26 PM4/10/20
to Google Apps Script Community
This may help:
function doGet(e) {
//var value = "jesus";
return HtmlService.createHtmlOutputFromFile('searchbox').setSandboxMode(HtmlService.SandboxMode.IFRAME); //instantiates, then claps out after return
 var gotResults = getDriveFiles(DriveApp.getFolderById('1e9aI6k3vn3n4oI1wFewdK3NarsaCnapH'),e);//e.parameter.q);
 var output = HtmlService.createTemplateFromFile('searchres');
 output.results = gotResults;
 output.query = e;//.parameter.q;
 return output.evaluate();

Alan Wells

Apr 10, 2020, 6:25:51 PM4/10/20
to Google Apps Script Community
Sorry, but I still don't understand what you are trying to do.  Maybe someone else can help.

Alistair George

Apr 12, 2020, 7:54:47 PM4/12/20
to Google Apps Script Community
Ive now gotten a callback to script thanks to Alan.

But I am finding that it seems impossible to use 2 calls to htmlservice.

eg the first call in doget() is to instantiate a html search box and return the value of search to script.

the second call, is the callback routine where I create a new htmlservice to display the search data, or I create and fill a sheet with the callback data (which works fine).

So, now Ive got the spreadsheet, can I insert it into same page as the previous searchbox html? It doesnt seem possible to me without using another call to htmlservice?

Alan Wells

Apr 12, 2020, 8:12:23 PM4/12/20
to Google Apps Script Community
If you want to get a value or some content from the server after the HTML has initially loaded and put that content into the HTML then you could attach a search string to the url of the Web App and refresh the browser tab:


Then in the doGet(e) function you can get the value and return something specific to that setting.

If you don't want to refresh the browser tab, then you can make a:

The function name doGet() is a reserved function name.  It's reserved for the GET request to the published Web App url.
You can call the doGet() function from another function, but it won't cause anything to happen in the browser.

Alan Wells

Apr 12, 2020, 8:28:49 PM4/12/20
to Google Apps Script Community
You can make a GET request to doGet() in some other way than in the browser address bar and get content returned, but you'd need to use


to send the return value/content.
Reply all
Reply to author
0 new messages