1

With Apps Script, it's not allowed to use iframes or AJAX calls. So, I was hoping to restructure my script. Basically, it's just supposed to be a single file chooser.

function doGet(e)
{
  return HtmlService.createHtmlOutputFromFile('index');
}


function browse(e)
{
  var use_root_folder = typeof(e.parameter.folder_id) == "undefined";

  var base_folder;
  if(use_root_folder)
  {
    base_folder = DriveApp.getRootFolder();
  }
  else
  {
    base_folder = DriveApp.getFolderById(e.parameter.folder_id);
  }
  //more code...
}

In sample code on apps script, it looks like I'm supposed to create an html file and put this in it...

<script>
  google.script.run.browse();
</script>

Except the "e" argument is only available from within the actual script and not the html file? How would I go about passing a query string parameter from within the HTML file back to the script?

1 Answer 1

2

When using google.script.run, you pass variables directly. So you can simply call browser() with the ID of the folder you want.

In the script file:

function browse(folderID)
{
  var use_root_folder = typeof(folderID) == "undefined";

  var base_folder;
  if(use_root_folder)
  {
    base_folder = DriveApp.getRootFolder();
  }
  else
  {
    base_folder = DriveApp.getFolderById(folderID);
  }
  //more code...
}

And in the HTML file:

<script>
  google.script.run.browse(selectedFolderId);
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks...what's not really clear from the documentation is that top-level vars are exposed from within the template <? ?> code...I ended up just putting stuff at the top level and managing it that way. So while I knew I could pass something like selectedFolderId to my fn...I didn't know that if I put selectedFolderId at top-level scope that it would be exposed to the template

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.