Skip to content

Instantly share code, notes, and snippets.

@kurtkaiser
Created February 16, 2019 19:55
Show Gist options
  • Save kurtkaiser/dd263991730624b7e94ac898d0f6a9c2 to your computer and use it in GitHub Desktop.
Save kurtkaiser/dd263991730624b7e94ac898d0f6a9c2 to your computer and use it in GitHub Desktop.
Properties in Google Apps Script is confusing. At least it was for me. I honestly spent a year avoiding using properties, I found saving variables as properties very frustrating. I use properties often and wanted to make a quick introduction to how properties in Apps Script work.
// Kurt Kaiser
// kurtkaiser.us
// All Rights Reserved, 2019
var scriptProperties = PropertiesService.getScriptProperties();
function onOpen(){
var ui = SpreadsheetApp.getUi();
var response = ui.prompt('What is your favorite color?', ui.ButtonSet.OK);
scriptProperties.setProperty('color', response.getResponseText());
ui.alert('Favorite color: ' + scriptProperties.getProperty('color'));
}
function myAlert(){
var ui = SpreadsheetApp.getUi();
ui.alert('Favorite color: ' + scriptProperties.getProperty('color'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment