LoginSignup
31
24

More than 5 years have passed since last update.

GASのProperties Serviceを使ってスクリプトのプロパティを読み書きをする

Last updated at Posted at 2018-09-04

GASのプロジェクトプロパティを変更する際に、[ファイル] - [プロジェクトのプロパティ] - [スクリプトのプロパティ] から変更する以外に、PropertiesServiceを使う方法があったのでメモ。

データの保存

単一の値を保存するにはProperties.setProperty(key, value)を使う。

PropertiesService.getScriptProperties().setProperty("key","value");

スクリーンショット 2018-09-04 14.05.34.png

データ変更時は同一キー名で上書きするだけでOK。

データの読み込み

単一の値を取得するにはProperties.getProperty(key)を使う。

var value = PropertiesService.getScriptProperties().getProperty("key");
Logger.log(value);

スクリーンショット 2018-09-04 14.15.22.png

注意点

プロパティの値はすべて文字列として保存される。
valueに数値など文字列以外のデータ型を渡しても、取得時は文字列として扱われる点に注意。

Data format
The Properties service stores all data as strings in key-value pairs. Data types that are not already strings are automatically converted to strings, including methods contained within saved objects.
Properties Service  |  Apps Script  |  Google Developers

参考

Class PropertiesService  |  Apps Script  |  Google Developers

31
24
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
24