LoginSignup
16
6

More than 5 years have passed since last update.

GASのPropertiesServiceのスコープ

Last updated at Posted at 2018-01-15

この話は一体

この記事はGASのPropertiesServiceのスコープを実際にアドオンつくって検証してみた話です。

前提

PropertiesServiceはGAS内のlocalstorage的なデータストアのことです。
このストレージタイプは3種類(Document/Script/User)あってそれぞれドキュメントにはこう書かれてます。

ストレージタイプ 説明
DocumentPropeties Gets a property store (for this script only) that all users can access within the open document, spreadsheet, or form.
ScriptPropeties Gets a property store that all users can access, but only within this script.
UserProperties Gets a property store that only the current user can access, and only within this script.

実験手順

A-spreadsheetとB-spreadsheetのふたつのシートを使ってアドオンでPropertiesService使って保持したデータの表示可否をチェックした。
また、アドオン化したscript idが配布後のユーザー間でも同じかどうかチェックした。

結果

script idについて

script idはAさんとBさんにアドオン配布後に確認したところ、両方で同じIDを示していたため、両者のscriptは同じものと扱われる

propertiesのスコープについて

AさんがA-spreadsheetのそれぞれのPropetiesに追加して、それぞれをアドオンで確認したところ

追加したところ AさんがA-spreadsheet見た時 AさんがB-spreadsheet見た時 BさんがA-spreadsheet見た時 BさんがB-spreadsheet見た時
DocumentPropeties 見える 見えない 見える 見えない
ScriptPropeties 見える 見える 見える 見える
UserProperties 見える 見える 見えない 見えない

まとめ

  • scriptをアドオン化して配布した場合でもscriptはすべて同一のものとして扱われ、ユーザー間でScriptPropertiesを共有することになるのでアドオン設計時には注意が必要。
  • DocumentPropertiesはユーザーに依存しない。
  • UserPropertiesはドキュメントに依存しない。

現場からは以上です。

16
6
0

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
16
6