Class Properties

プロパティ

プロパティ オブジェクトは、ユーザー、ドキュメント、スクリプトのプロパティにアクセスするためのインターフェースとして機能します。特定のプロパティ型は、スクリプトが PropertiesService.getDocumentProperties()PropertiesService.getUserProperties()PropertiesService.getScriptProperties() の 3 つの PropertiesService メソッドのうちどれを呼び出すかによって異なります。スクリプト間でプロパティを共有することはできません。プロパティ タイプについて詳しくは、プロパティ サービスのガイドをご覧ください。

Methods

メソッド戻り値の型概要
deleteAllProperties()Properties現在の Properties ストアのすべての宿泊施設を削除します。
deleteProperty(key)Properties現在の Properties ストア内の指定されたキーを持つプロパティを削除します。
getKeys()String[]現在の Properties ストア内のすべての鍵を取得します。
getProperties()Object現在の Properties ストア内のすべての Key-Value ペアのコピーを取得します。
getProperty(key)String現在の Properties ストア内の指定されたキーに関連付けられている値を取得します。そのようなキーが存在しない場合は null を取得します。
setProperties(properties)Properties現在の Properties ストアの指定されたオブジェクトのすべての Key-Value ペアを設定します。
setProperties(properties, deleteAllOthers)Properties現在の Properties ストアの指定されたオブジェクトのすべての Key-Value ペアを設定します。必要に応じてストア内の他のすべてのプロパティを削除します。
setProperty(key, value)Properties現在の Properties ストア内に、指定された Key-Value ペアを設定します。

詳細なドキュメント

deleteAllProperties()

現在の Properties ストアのすべてのプロパティを削除します。

// Deletes all user properties.
var userProperties = PropertiesService.getUserProperties();
userProperties.deleteAllProperties();

リターン

Properties - この Properties ストア(チェーン用)


deleteProperty(key)

現在の Properties ストア内の指定されたキーを持つプロパティを削除します。

// Deletes the user property 'nickname'.
var userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty('nickname');

パラメータ

名前説明
keyString削除するプロパティのキー。

リターン

Properties - この Properties ストア(チェーン用)


getKeys()

現在の Properties ストア内のすべての鍵を取得します。

// Sets several properties, then logs the value of each key.
var scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({
  'cow': 'moo',
  'sheep': 'baa',
  'chicken': 'cluck'
});
var keys = scriptProperties.getKeys();
Logger.log('Animals known:');
for (var i = 0; i < keys.length; i++) {
  Logger.log(keys[i]);
}

リターン

String[] - 現在の Properties ストア内のすべてのキーの配列


getProperties()

現在の Properties ストア内のすべての Key-Value ペアのコピーを取得します。返されるオブジェクトは、店舗のライブビューではありません。したがって、返されたオブジェクトのプロパティを変更しても、ストレージ内のプロパティは自動的に更新されません。その逆も同様です。

// Sets several script properties, then retrieves them and logs them.
var scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperties({
  'cow': 'moo',
  'sheep': 'baa',
  'chicken': 'cluck'
});

var animalSounds = scriptProperties.getProperties();

// Logs:
// A chicken goes cluck!
// A cow goes moo!
// A sheep goes baa!
for (var kind in animalSounds) {
  Logger.log('A %s goes %s!', kind, animalSounds[kind]);
}

リターン

Object - 現在の Properties ストア内のすべての Key-Value ペアのコピー


getProperty(key)

現在の Properties ストア内の指定されたキーに関連付けられている値を取得します。キーが存在しない場合は null を取得します。

// Gets the user property 'nickname'.
var userProperties = PropertiesService.getUserProperties();
var nickname = userProperties.getProperty('nickname');
Logger.log(nickname);

パラメータ

名前説明
keyString取得するプロパティ値のキー

リターン

String - 現在の Properties ストアの特定のキーに関連付けられている値


setProperties(properties)

現在の Properties ストア内にある指定されたオブジェクトのすべての Key-Value ペアを設定します。

// Sets multiple user properties at once.
var userProperties = PropertiesService.getUserProperties();
var newProperties = {nickname: 'Bob', region: 'US', language: 'EN'};
userProperties.setProperties(newProperties);

パラメータ

名前説明
propertiesObject設定する Key-Value ペアを含むオブジェクト。

リターン

Properties - この Properties ストア(チェーン用)


setProperties(properties, deleteAllOthers)

現在の Properties ストアの指定されたオブジェクトのすべての Key-Value ペアを設定します。必要に応じてストア内の他のすべてのプロパティを削除します。

// Sets multiple user properties at once while deleting all other user properties.
var userProperties = PropertiesService.getUserProperties();
var newProperties = {nickname: 'Bob', region: 'US', language: 'EN'};
userProperties.setProperties(newProperties, true);

パラメータ

名前説明
propertiesObject設定する Key-Value ペアを含むオブジェクト。
deleteAllOthersBooleanプロパティ オブジェクトの他のすべての Key-Value ペアを削除する場合は true、それ以外の場合は false を指定します。

リターン

Properties - この Properties ストア(チェーン用)


setProperty(key, value)

現在の Properties ストア内に、指定された Key-Value ペアを設定します。

// Sets the user property 'nickname' to 'Bobby'.
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('nickname', 'Bobby');

パラメータ

名前説明
keyStringプロパティのキー
valueStringキーに関連付ける値

リターン

Properties - この Properties ストア(チェーン用)