Class Properties

プロパティ

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

メソッド

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

詳細なドキュメント

deleteAllProperties()

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

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

戻る

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


deleteProperty(key)

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

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

パラメータ

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

戻る

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


getKeys()

現在の 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 ストア内のすべてのキーの配列


getProperties()

現在の 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 ペアのコピー


getProperty(key)

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

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

パラメータ

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

戻る

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


setProperties(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);

パラメータ

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

戻る

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


setProperties(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);

パラメータ

名前説明
propertiesObject設定する Key-Value ペアを含むオブジェクト
deleteAllOthersBooleantrue: プロパティ オブジェクト内の他のすべての Key-Value ペアを削除します。false: 削除しません。

戻る

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


setProperty(key, value)

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

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

パラメータ

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

戻る

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