Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtkaiser/08b5431af1a6542e44c8f46f4d421ddd to your computer and use it in GitHub Desktop.
Save kurtkaiser/08b5431af1a6542e44c8f46f4d421ddd to your computer and use it in GitHub Desktop.
Google Apps Script Properties Service Video Demo
// Code.gs by Kurt Kaiser
var scriptProperties = PropertiesService.getScriptProperties();
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Properties Demo')
.addItem('Show Sidebar', 'showFormSidebar')
.addToUi();
}
function showFormSidebar() {
var html = HtmlService.createHtmlOutputFromFile('Form')
.setTitle('Properties Demo')
SpreadsheetApp.getUi()
.showSidebar(html);
}
function saveSidebar(sideData){
scriptProperties.setProperty('myColor', sideData.favColor);
scriptProperties.setProperty('myAnimal', sideData.animal);
}
<!-- Form.html -->
<!DOCTYPE html>
<html>
<body style="background: #0D9; color: blue">
<form>
<h2> Favorite Color</h2>
<input type="text" name="favColor" value="none"/>
<h2>Animal</h2>
<select name="animal">
<option value="bird">Bird</option>
<option value="dog">Dog</option>
<option value="fish">Fish</option>
</select>
<br><br>
<button id="submitBtn" type="button" onClick="sidebarSubmit()">Submit</button>
</form>
</body>
<script>
function sidebarSubmit(){
google.script.run.saveSidebar(document.forms[0]);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment