Class Properties

プロパティ

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

メソッド

メソッド戻り値の型概要
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.
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)

現在の Properties ストアで、指定したオブジェクトのすべての Key-Value ペアを設定します。

// 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)

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

// 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 ペアを含むオブジェクト
deleteAllOthersBooleanプロパティ オブジェクト内の他のすべての Key-Value ペアを削除する場合は true、削除しない場合は 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 ストア