properties オブジェクトは、ユーザー、ドキュメント、スクリプトのプロパティにアクセスするためのインターフェースとして機能します。具体的なプロパティの型は、スクリプトで呼び出された Properties
の 3 つのメソッド(Properties
、Properties
、Properties
)のいずれかによって異なります。プロパティはスクリプト間で共有できません。プロパティ タイプの詳細については、プロパティ サービスのガイドをご覧ください。
メソッド
メソッド | 戻り値の型 | 概要 |
---|---|---|
delete | Properties | 現在の Properties ストア内のすべてのプロパティを削除します。 |
delete | Properties | 現在の Properties ストアで、指定されたキーを持つプロパティを削除します。 |
get | String[] | 現在の Properties ストア内のすべてのキーを取得します。 |
get | Object | 現在の Properties ストア内のすべての Key-Value ペアのコピーを取得します。 |
get | String | 現在の Properties ストアで指定されたキーに関連付けられている値を取得します。そのようなキーが存在しない場合は null を返します。 |
set | Properties | 指定したオブジェクトのすべての Key-Value ペアを現在の Properties ストアに設定します。 |
set | Properties | 指定されたオブジェクトのすべての Key-Value ペアを現在の Properties ストアに設定します。必要に応じて、ストア内の他のすべてのプロパティを削除します。 |
set | Properties | 現在の Properties ストアに指定された Key-Value ペアを設定します。 |
詳細なドキュメント
delete All Properties()
現在の Properties
ストア内のすべてのプロパティを削除します。
// Deletes all user properties. const userProperties = PropertiesService.getUserProperties(); userProperties.deleteAllProperties();
戻る
Properties
- この Properties
ストア(チェーン用)
delete Property(key)
現在の Properties
ストアで、指定されたキーを持つプロパティを削除します。
// Deletes the user property 'nickname'. const userProperties = PropertiesService.getUserProperties(); userProperties.deleteProperty('nickname');
パラメータ
名前 | 型 | 説明 |
---|---|---|
key | String | 削除するプロパティのキー |
戻る
Properties
- この Properties
ストア(チェーン用)
get Keys()
現在の Properties
ストア内のすべてのキーを取得します。
// Sets several properties, then logs the value of each key. const scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ cow: 'moo', sheep: 'baa', chicken: 'cluck', }); const keys = scriptProperties.getKeys(); Logger.log('Animals known:'); for (let i = 0; i < keys.length; i++) { Logger.log(keys[i]); }
戻る
String[]
- 現在の Properties
ストア内のすべてのキーの配列
get Properties()
現在の Properties
ストア内のすべての Key-Value ペアのコピーを取得します。返されるオブジェクトは、ストアのライブビューではありません。したがって、返されたオブジェクトのプロパティを変更しても、ストレージ内のプロパティは自動的に更新されません。また、その逆も同様です。
// Sets several script properties, then retrieves them and logs them. const scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ cow: 'moo', sheep: 'baa', chicken: 'cluck', }); const animalSounds = scriptProperties.getProperties(); // Logs: // A chicken goes cluck! // A cow goes moo! // A sheep goes baa! for (const kind in animalSounds) { Logger.log('A %s goes %s!', kind, animalSounds[kind]); }
戻る
Object
- 現在の Properties
ストア内のすべての Key-Value ペアのコピー
get Property(key)
現在の Properties
ストアで指定されたキーに関連付けられている値を取得します。そのようなキーが存在しない場合は null
を返します。
// Gets the user property 'nickname'. const userProperties = PropertiesService.getUserProperties(); const nickname = userProperties.getProperty('nickname'); Logger.log(nickname);
パラメータ
名前 | 型 | 説明 |
---|---|---|
key | String | 取得するプロパティ値のキー |
戻る
String
- 現在の Properties
ストアで指定されたキーに関連付けられている値
set Properties(properties)
指定されたオブジェクトのすべての Key-Value ペアを現在の Properties
ストアに設定します。
// Sets multiple user properties at once. const userProperties = PropertiesService.getUserProperties(); const newProperties = { nickname: 'Bob', region: 'US', language: 'EN' }; userProperties.setProperties(newProperties);
パラメータ
名前 | 型 | 説明 |
---|---|---|
properties | Object | 設定する Key-Value ペアを含むオブジェクト |
戻る
Properties
- この Properties
ストア(チェーン用)
set Properties(properties, deleteAllOthers)
指定されたオブジェクトのすべての Key-Value ペアを現在の Properties
ストアに設定します。必要に応じて、ストア内の他のすべてのプロパティを削除します。
// Sets multiple user properties at once while deleting all other user // properties. const userProperties = PropertiesService.getUserProperties(); const newProperties = { nickname: 'Bob', region: 'US', language: 'EN' }; userProperties.setProperties(newProperties, true);
パラメータ
名前 | 型 | 説明 |
---|---|---|
properties | Object | 設定する Key-Value ペアを含むオブジェクト |
delete | Boolean | true : プロパティ オブジェクト内の他のすべての Key-Value ペアを削除します。false : 削除しません。 |
戻る
Properties
- この Properties
ストア(チェーン用)
set Property(key, value)
現在の Properties
ストアに指定された Key-Value ペアを設定します。
// Sets the user property 'nickname' to 'Bobby'. const userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('nickname', 'Bobby');
パラメータ
名前 | 型 | 説明 |
---|---|---|
key | String | プロパティのキー |
value | String | キーに関連付ける値 |
戻る
Properties
- この Properties
ストア(チェーン用)