Quickly and Easily Save Properties Google Apps Script

Quickly and Easily Save Properties Google Apps Script

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. I walk through the basics in this tutorial video of how to save a variable as a property and how to call it up when needed.

Once you master the basics, make sure to check out my in-depth tutorial on properties in Google Apps Script.

The code I wrote in the video is posted below.  Feel free to copy / steal / edit / mock the code to your liking.

Code Text

// 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'));
}

Leave a Reply

Your email address will not be published. Required fields are marked *