Class Properties

Properties

Das Objekt „Properties“ dient als Schnittstelle für den Zugriff auf Nutzer-, Dokument- oder Skriptattribute. Der spezifische Attributtyp hängt davon ab, welche der drei Methoden von PropertiesService das Skript aufgerufen hat: PropertiesService.getDocumentProperties(), PropertiesService.getUserProperties(), oder PropertiesService.getScriptProperties(). Attribute können nicht zwischen Skripts freigegeben werden. Weitere Informationen zu Attributtypen finden Sie im Leitfaden zum Properties-Dienst.

Methoden

MethodeRückgabetypKurzbeschreibung
deleteAllProperties()PropertiesLöscht alle Attribute im aktuellen Properties-Speicher.
deleteProperty(key)PropertiesLöscht das Attribut mit dem angegebenen Schlüssel im aktuellen Properties-Speicher.
getKeys()String[]Ruft alle Schlüssel im aktuellen Properties-Speicher ab.
getProperties()ObjectRuft eine Kopie aller Schlüssel/Wert-Paare im aktuellen Properties-Speicher ab.
getProperty(key)StringRuft den Wert ab, der dem angegebenen Schlüssel im aktuellen Properties-Speicher zugeordnet ist. Wenn kein solcher Schlüssel vorhanden ist, wird null zurückgegeben.
setProperties(properties)PropertiesLegt alle Schlüssel/Wert-Paare aus dem angegebenen Objekt im aktuellen Properties-Speicher fest.
setProperties(properties, deleteAllOthers)PropertiesLegt alle Schlüssel/Wert-Paare aus dem angegebenen Objekt im aktuellen Properties-Speicher fest und löscht optional alle anderen Attribute im Speicher.
setProperty(key, value)PropertiesLegt das angegebene Schlüssel/Wert-Paar im aktuellen Properties-Speicher fest.

Detaillierte Dokumentation

deleteAllProperties()

Löscht alle Attribute im aktuellen Properties-Speicher.

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

Rückflug

Properties : Dieser Properties-Speicher für die Verkettung


deleteProperty(key)

Löscht das Attribut mit dem angegebenen Schlüssel im aktuellen Properties-Speicher.

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

Parameter

NameTypBeschreibung
keyStringDer Schlüssel für das zu löschende Attribut

Rückflug

Properties : Dieser Properties-Speicher für die Verkettung


getKeys()

Ruft alle Schlüssel im aktuellen Properties-Speicher ab.

// 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]);
}

Rückflug

String[] : Ein Array aller Schlüssel im aktuellen Properties-Speicher


getProperties()

Ruft eine Kopie aller Schlüssel/Wert-Paare im aktuellen Properties-Speicher ab. Das zurückgegebene Objekt ist keine Live-Ansicht des Speichers. Wenn Sie die Attribute im zurückgegebenen Objekt ändern, werden sie daher nicht automatisch im Speicher aktualisiert und umgekehrt.

// 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]);
}

Rückflug

Object : Eine Kopie aller Schlüssel/Wert-Paare im aktuellen Properties-Speicher


getProperty(key)

Ruft den Wert ab, der dem angegebenen Schlüssel im aktuellen Properties-Speicher zugeordnet ist. Wenn kein solcher Schlüssel vorhanden ist, wird null zurückgegeben.

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

Parameter

NameTypBeschreibung
keyStringDer Schlüssel für den abzurufenden Attributwert

Rückflug

String : Der Wert, der dem angegebenen Schlüssel im aktuellen Properties-Speicher zugeordnet ist


setProperties(properties)

Legt alle Schlüssel/Wert-Paare aus dem angegebenen Objekt im aktuellen Properties-Speicher fest.

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

Parameter

NameTypBeschreibung
propertiesObjectEin Objekt mit Schlüssel/Wert-Paaren, die festgelegt werden sollen

Rückflug

Properties : Dieser Properties-Speicher für die Verkettung


setProperties(properties, deleteAllOthers)

Legt alle Schlüssel/Wert-Paare aus dem angegebenen Objekt im aktuellen Properties-Speicher fest und löscht optional alle anderen Attribute im Speicher.

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

Parameter

NameTypBeschreibung
propertiesObjectEin Objekt mit Schlüssel/Wert-Paaren, die festgelegt werden sollen
deleteAllOthersBooleantrue zum Löschen aller anderen Schlüssel/Wert-Paare im Objekt „Properties“ , andernfalls false

Rückflug

Properties : Dieser Properties-Speicher für die Verkettung


setProperty(key, value)

Legt das angegebene Schlüssel/Wert-Paar im aktuellen Properties-Speicher fest.

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

Parameter

NameTypBeschreibung
keyStringDer Schlüssel für das Attribut
valueStringDer Wert, der dem Schlüssel zugeordnet werden soll

Rückflug

Properties : Dieser Properties-Speicher für die Verkettung