Class PropertiesService

PropertiesService

Allows scripts to store simple data in key-value pairs scoped to one script, one user of a script, or one document in which an add-on is used. Properties cannot be shared between scripts. For more information about when to use each type of property, see the guide to the Properties service.

// Sets three properties of different types.
const documentProperties = PropertiesService.getDocumentProperties();
const scriptProperties = PropertiesService.getScriptProperties();
const userProperties = PropertiesService.getUserProperties();

documentProperties.setProperty('DAYS_TO_FETCH', '5');
scriptProperties.setProperty(
    'SERVER_URL',
    'http://www.example.com/MyWeatherService/',
);
userProperties.setProperty('DISPLAY_UNITS', 'metric');

Methods

MethodReturn typeBrief description
getDocumentProperties()PropertiesGets a property store (for this script only) that all users can access within the open document, spreadsheet, or form.
getScriptProperties()PropertiesGets a property store that all users can access, but only within this script.
getUserProperties()PropertiesGets a property store that only the current user can access, and only within this script.

Detailed documentation

getDocumentProperties()

Gets a property store (for this script only) that all users can access within the open document, spreadsheet, or form. It is only available if the script is published and executing as an add-on or if it is bound to a Google file type. When document properties are not available this method returns null. Document properties created by a script are not accessible outside that script, even by other scripts accessing the same document.

Return

Properties — a property store for this script only that all users of the current document can access, or null if the script is not either an add-on or bound to a Google Workspace file


getScriptProperties()

Gets a property store that all users can access, but only within this script.

Return

Properties — a property store that all users of the script can access


getUserProperties()

Gets a property store that only the current user can access, and only within this script.

Return

Properties — a property store that only the current user of the script can access