Class Properties

  • The properties object allows access to user, document, or script properties through methods of thePropertiesService.

  • Properties cannot be shared between different scripts.

  • TheProperties object includes methods for deleting properties, retrieving keys or all properties, and setting individual or multiple properties.

Properties

The properties object acts as the interface to access user, document, or script properties. Thespecific property type depends on which of the three methods ofPropertiesService thescript called:PropertiesService.getDocumentProperties(),PropertiesService.getUserProperties(), orPropertiesService.getScriptProperties().Properties cannot be shared between scripts. For more information about property types, see theguide to the Properties service.

Methods

MethodReturn typeBrief description
deleteAllProperties()PropertiesDeletes all properties in the currentProperties store.
deleteProperty(key)PropertiesDeletes the property with the given key in the currentProperties store.
getKeys()String[]Gets all keys in the currentProperties store.
getProperties()ObjectGets a copy of all key-value pairs in the currentProperties store.
getProperty(key)StringGets the value associated with the given key in the currentProperties store, ornull if no such key exists.
setProperties(properties)PropertiesSets all key-value pairs from the given object in the currentProperties store.
setProperties(properties, deleteAllOthers)PropertiesSets all key-value pairs from the given object in the currentProperties store,optionally deleting all other properties in the store.
setProperty(key, value)PropertiesSets the given key-value pair in the currentProperties store.

Detailed documentation

deleteAllProperties()

Deletes all properties in the currentProperties store.

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

Return

Properties — thisProperties store, for chaining


deleteProperty(key)

Deletes the property with the given key in the currentProperties store.

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

Parameters

NameTypeDescription
keyStringthe key for the property to delete

Return

Properties — thisProperties store, for chaining


getKeys()

Gets all keys in the currentProperties store.

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

Return

String[] — an array of all keys in the currentProperties store


getProperties()

Gets a copy of all key-value pairs in the currentProperties store. Note that thereturned object is not a live view of the store. Consequently, changing the properties on thereturned object will not automatically update them in storage, or vice versa.

// Sets several script properties, then retrieves them and logs them.constscriptProperties=PropertiesService.getScriptProperties();scriptProperties.setProperties({cow:'moo',sheep:'baa',chicken:'cluck',});constanimalSounds=scriptProperties.getProperties();// Logs:// A chicken goes cluck!// A cow goes moo!// A sheep goes baa!for(constkindinanimalSounds){Logger.log('A %s goes %s!',kind,animalSounds[kind]);}

Return

Object — a copy of all key-value pairs in the currentProperties store


getProperty(key)

Gets the value associated with the given key in the currentProperties store, ornull if no such key exists.

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

Parameters

NameTypeDescription
keyStringthe key for the property value to retrieve

Return

String — the value associated with the given key in the currentProperties store


setProperties(properties)

Sets all key-value pairs from the given object in the currentProperties store.

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

Parameters

NameTypeDescription
propertiesObjectan object containing key-values pairs to set

Return

Properties — thisProperties store, for chaining


setProperties(properties, deleteAllOthers)

Sets all key-value pairs from the given object in the currentProperties store,optionally deleting all other properties in the store.

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

Parameters

NameTypeDescription
propertiesObjectan object containing key-values pairs to set
deleteAllOthersBooleantrue to delete all other key-value pairs in the properties object;false to not

Return

Properties — thisProperties store, for chaining


setProperty(key, value)

Sets the given key-value pair in the currentProperties store.

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

Parameters

NameTypeDescription
keyStringthe key for the property
valueStringthe value to associate with the key

Return

Properties — thisProperties store, for chaining

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.