Skip to content

Instantly share code, notes, and snippets.

@CJOWood
Created February 18, 2018 04:52
Show Gist options
  • Save CJOWood/36a16d127e026012fea5eb68c8280d2c to your computer and use it in GitHub Desktop.
Save CJOWood/36a16d127e026012fea5eb68c8280d2c to your computer and use it in GitHub Desktop.
Using withSuccessHandler to Return Array and Make List
function onOpen() {
FormApp.getUi() // Or DocumentApp or FormApp.
.createMenu('Custom Menu')
.addItem('Show sidebar', 'showSidebar')
.addToUi();
}
function showSidebar() {
Logger.log("Showing Sidebar...");
var html = HtmlService.createHtmlOutputFromFile('test')
.setTitle('My custom sidebar')
.setWidth(300);
FormApp.getUi() // Or DocumentApp or FormApp.
.showSidebar(html);
}
function getSomeData() {
return [["Cell 1"],["Cell 2"],["Cell 3"],["Cell 4"],["Cell 5"]];
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
google.script.run.withSuccessHandler(onSuccess)
.getSomeData();
function onSuccess(data) {
var div = document.getElementById('output');
var list = document.createElement('ul'); // Create a <li> node
for(var i = 0; i < data.length; i++){
var item = document.createElement('li');
item.appendChild(document.createTextNode(data[i]));
list.appendChild(item);
}
div.appendChild(list);
}
</script>
</head>
<body>
<div id="output">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment