// 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 current Properties store
getProperties()
Gets a copy of all key-value pairs in the current Properties store. Note that the
returned object is not a live view of the store. Consequently, changing the properties on the
returned 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 current Properties store
getProperty(key)
Gets the value associated with the given key in the current Properties store, or null if no such key exists.
// Gets the user property 'nickname'.constuserProperties=PropertiesService.getUserProperties();constnickname=userProperties.getProperty('nickname');Logger.log(nickname);
Parameters
Name
Type
Description
key
String
the key for the property value to retrieve
Return
String — the value associated with the given key in the current Properties store
setProperties(properties)
Sets all key-value pairs from the given object in the current Properties store.
// Sets multiple user properties at once.constuserProperties=PropertiesService.getUserProperties();constnewProperties={nickname:'Bob',region:'US',language:'EN'};userProperties.setProperties(newProperties);
Sets all key-value pairs from the given object in the current Properties 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
Name
Type
Description
properties
Object
an object containing key-values pairs to set
deleteAllOthers
Boolean
true to delete all other key-value pairs in the properties
object; false to not
Sets the given key-value pair in the current Properties store.
// Sets the user property 'nickname' to 'Bobby'.constuserProperties=PropertiesService.getUserProperties();userProperties.setProperty('nickname','Bobby');
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eProperties\u003c/code\u003e object provides an interface to access user, document, or script properties based on the selected method from \u003ccode\u003ePropertiesService\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eProperties are isolated to individual scripts and cannot be shared.\u003c/p\u003e\n"],["\u003cp\u003eThis service allows scripts to store and retrieve data persistently, offering methods for setting, getting, and deleting properties.\u003c/p\u003e\n"],["\u003cp\u003eIt's important to note that \u003ccode\u003egetProperties()\u003c/code\u003e returns a copy, so modifications won't directly affect the stored properties.\u003c/p\u003e\n"],["\u003cp\u003eMethods for bulk operations like \u003ccode\u003esetProperties()\u003c/code\u003e and \u003ccode\u003edeleteAllProperties()\u003c/code\u003e are available for efficiency.\u003c/p\u003e\n"]]],[],null,["# Class Properties\n\nProperties\n\nThe properties object acts as the interface to access user, document, or script properties. The\nspecific property type depends on which of the three methods of [PropertiesService](/apps-script/reference/properties/properties-service) the\nscript called: [PropertiesService.getDocumentProperties()](/apps-script/reference/properties/properties-service#getDocumentProperties()), [PropertiesService.getUserProperties()](/apps-script/reference/properties/properties-service#getUserProperties()), or [PropertiesService.getScriptProperties()](/apps-script/reference/properties/properties-service#getScriptProperties()).\nProperties cannot be shared between scripts. For more information about property types, see the\n[guide to the Properties service](/apps-script/guides/properties). \n\n### Methods\n\n| Method | Return type | Brief description |\n|------------------------------------------------------------------------------|-----------------|------------------------------------------------------------------------------------------------------------------------------------------|\n| [deleteAllProperties()](#deleteAllProperties()) | [Properties](#) | Deletes all properties in the current `Properties` store. |\n| [deleteProperty(key)](#deleteProperty(String)) | [Properties](#) | Deletes the property with the given key in the current `Properties` store. |\n| [getKeys()](#getKeys()) | `String[]` | Gets all keys in the current `Properties` store. |\n| [getProperties()](#getProperties()) | `Object` | Gets a copy of all key-value pairs in the current `Properties` store. |\n| [getProperty(key)](#getProperty(String)) | `String` | Gets the value associated with the given key in the current `Properties` store, or `null` if no such key exists. |\n| [setProperties(properties)](#setProperties(Object)) | [Properties](#) | Sets all key-value pairs from the given object in the current `Properties` store. |\n| [setProperties(properties, deleteAllOthers)](#setProperties(Object,Boolean)) | [Properties](#) | Sets all key-value pairs from the given object in the current `Properties` store, optionally deleting all other properties in the store. |\n| [setProperty(key, value)](#setProperty(String,String)) | [Properties](#) | Sets the given key-value pair in the current `Properties` store. |\n\nDetailed documentation\n----------------------\n\n### `delete``All``Properties()`\n\nDeletes all properties in the current `Properties` store.\n\n```javascript\n// Deletes all user properties.\nconst userProperties = PropertiesService.getUserProperties();\nuserProperties.deleteAllProperties();\n```\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `delete``Property(key)`\n\nDeletes the property with the given key in the current `Properties` store.\n\n```javascript\n// Deletes the user property 'nickname'.\nconst userProperties = PropertiesService.getUserProperties();\nuserProperties.deleteProperty('nickname');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|------------------------------------|\n| `key` | `String` | the key for the property to delete |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `get``Keys()`\n\nGets all keys in the current `Properties` store.\n\n```javascript\n// Sets several properties, then logs the value of each key.\nconst scriptProperties = PropertiesService.getScriptProperties();\nscriptProperties.setProperties({\n cow: 'moo',\n sheep: 'baa',\n chicken: 'cluck',\n});\nconst keys = scriptProperties.getKeys();\nLogger.log('Animals known:');\nfor (let i = 0; i \u003c keys.length; i++) {\n Logger.log(keys[i]);\n}\n```\n\n#### Return\n\n\n`String[]` --- an array of all keys in the current `Properties` store\n\n*** ** * ** ***\n\n### `get``Properties()`\n\nGets a copy of all key-value pairs in the current `Properties` store. Note that the\nreturned object is not a live view of the store. Consequently, changing the properties on the\nreturned object will not automatically update them in storage, or vice versa.\n\n```javascript\n// Sets several script properties, then retrieves them and logs them.\nconst scriptProperties = PropertiesService.getScriptProperties();\nscriptProperties.setProperties({\n cow: 'moo',\n sheep: 'baa',\n chicken: 'cluck',\n});\n\nconst animalSounds = scriptProperties.getProperties();\n\n// Logs:\n// A chicken goes cluck!\n// A cow goes moo!\n// A sheep goes baa!\nfor (const kind in animalSounds) {\n Logger.log('A %s goes %s!', kind, animalSounds[kind]);\n}\n```\n\n#### Return\n\n\n`Object` --- a copy of all key-value pairs in the current `Properties` store\n\n*** ** * ** ***\n\n### `get``Property(key)`\n\nGets the value associated with the given key in the current `Properties` store, or `null` if no such key exists.\n\n```javascript\n// Gets the user property 'nickname'.\nconst userProperties = PropertiesService.getUserProperties();\nconst nickname = userProperties.getProperty('nickname');\nLogger.log(nickname);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|--------------------------------------------|\n| `key` | `String` | the key for the property value to retrieve |\n\n#### Return\n\n\n`String` --- the value associated with the given key in the current `Properties` store\n\n*** ** * ** ***\n\n### `set``Properties(properties)`\n\nSets all key-value pairs from the given object in the current `Properties` store.\n\n```javascript\n// Sets multiple user properties at once.\nconst userProperties = PropertiesService.getUserProperties();\nconst newProperties = {\n nickname: 'Bob',\n region: 'US',\n language: 'EN'\n};\nuserProperties.setProperties(newProperties);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------|----------|----------------------------------------------|\n| `properties` | `Object` | an object containing key-values pairs to set |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `set``Properties(properties, deleteAllOthers)`\n\nSets all key-value pairs from the given object in the current `Properties` store,\noptionally deleting all other properties in the store.\n\n```javascript\n// Sets multiple user properties at once while deleting all other user\n// properties.\nconst userProperties = PropertiesService.getUserProperties();\nconst newProperties = {\n nickname: 'Bob',\n region: 'US',\n language: 'EN'\n};\nuserProperties.setProperties(newProperties, true);\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|-----------------------|-----------|-------------------------------------------------------------------------------------|\n| `properties` | `Object` | an object containing key-values pairs to set |\n| `delete``All``Others` | `Boolean` | `true` to delete all other key-value pairs in the properties object; `false` to not |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining\n\n*** ** * ** ***\n\n### `set``Property(key, value)`\n\nSets the given key-value pair in the current `Properties` store.\n\n```javascript\n// Sets the user property 'nickname' to 'Bobby'.\nconst userProperties = PropertiesService.getUserProperties();\nuserProperties.setProperty('nickname', 'Bobby');\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|---------|----------|-------------------------------------|\n| `key` | `String` | the key for the property |\n| `value` | `String` | the value to associate with the key |\n\n#### Return\n\n\n[Properties](#) --- this `Properties` store, for chaining"]]