Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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

unsoluble_sugar
フルオタクエンジニア
https://unsolublesugar.com
topgate
Google技術を中心に取り扱う技術者集団
https://www.topgate.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした