Task guide
Store settings with PropertiesService
PropertiesService.getScriptProperties() stores small key-value settings with the Apps Script project. Save a setting once with setProperties(), then read it on every run with getProperty().
1 · Prepare
Put these pieces in place
- Open any Apps Script project. It can be one attached to a Sheet or a standalone project from script.google.com.
- Know where Project Settings is. It is the gear icon in the left sidebar, and its Script Properties section lists what this guide saves.
- Pick values you are comfortable sharing with everyone who can edit the project, because every editor can read the script properties.
Change these values
- Recipient property
REPORT_RECIPIENTThe name the script looks up. Capital letters with underscores make property names easy to spot in the code.
- Recipient value
you@example.comThe example address saved under that name. Replace it with the address you actually use.
- Title property
REPORT_TITLEThe name of the second setting, so you can see how several values are saved at once.
- Title value
Weekly reportThe example title saved under that name.
2 · Review before running
What the script can access and change
Permissions you approve
- Save and read small values stored inside this Apps Script project.
- These two functions do not read your Sheets, your Gmail, or your Drive, so the authorization dialog stays short.
Effects of one run
- saveSettings writes REPORT_RECIPIENT and REPORT_TITLE into the project, replacing whatever those two names held before.
- showSettings only reads and logs. It changes nothing.
- Neither function sends email or edits a document. Both are safe to repeat.
3 · Copy
Paste this into the Apps Script editor
Create or open a script file, replace the example values marked above, then save the project.
const RECIPIENT_PROPERTY = 'REPORT_RECIPIENT'; // The name the script looks up. Capital letters with underscores make property names easy to spot in the code.
const RECIPIENT_VALUE = 'you@example.com'; // The example address saved under that name. Replace it with the address you actually use.
const TITLE_PROPERTY = 'REPORT_TITLE'; // The name of the second setting, so you can see how several values are saved at once.
const TITLE_VALUE = 'Weekly report'; // The example title saved under that name.
function saveSettings() {
const properties = PropertiesService.getScriptProperties();
properties.setProperties({
[RECIPIENT_PROPERTY]: RECIPIENT_VALUE,
[TITLE_PROPERTY]: TITLE_VALUE
});
Logger.log('Saved ' + RECIPIENT_PROPERTY + ' as ' + RECIPIENT_VALUE);
Logger.log('Saved ' + TITLE_PROPERTY + ' as ' + TITLE_VALUE);
}
function showSettings() {
const properties = PropertiesService.getScriptProperties();
const recipient = properties.getProperty(RECIPIENT_PROPERTY);
if (!recipient) {
throw new Error(RECIPIENT_PROPERTY + ' is not set. Run saveSettings once, or add the property in Project Settings.');
}
const title = properties.getProperty(TITLE_PROPERTY) || TITLE_VALUE;
Logger.log(RECIPIENT_PROPERTY + ' is ' + recipient);
Logger.log(TITLE_PROPERTY + ' is ' + title);
} 4 · Run safely
Follow these steps in order
Paste both functions and run showSettings first
Choose showSettings and press Run before anything is saved. It stops with the message REPORT_RECIPIENT is not set. Nothing is stored or changed by this test.
Save the settings once
Choose saveSettings and run it. Open the Execution log to see the two saved values. You only need to run this function again when you want to overwrite the values from code.
Read them back
Run showSettings again. The log now prints both values. Every later run reads the saved values, so the code itself never has to change.
Edit a value without touching the code
Open Project Settings with the gear icon and scroll to Script Properties. Change REPORT_RECIPIENT there, save, and run showSettings once more to see the new value.
Know which store to pick
There are three stores. Script properties, used here, are shared by the project and every editor can see them. User properties keep a separate copy for each person who runs the script. Document properties belong to the one Sheet, Doc, or Form the script is attached to.
5 · Confirm
How to tell it worked
The Execution log shows REPORT_RECIPIENT is you@example.com and REPORT_TITLE is Weekly report, and Project Settings lists both names under Script Properties.
If the result is different
Troubleshooting
- The run fails with "REPORT_RECIPIENT is not set. Run saveSettings once, or add the property in Project Settings."
- That message means the name has no value yet. Run saveSettings, or add the name and value by hand under Project Settings, Script Properties.
- A saved number behaves like text.
- Property values are always text. Wrap the value in Number(...) when you need to do arithmetic with it.
- A colleague sees a value you thought was private.
- Script properties are visible to everyone who can edit the project. They are better than pasting a value into the code, but they are not a secret store. Keep anything private out of the project.
- The property disappeared.
- Properties belong to one script project. A copy of the Sheet or a new project starts with an empty list, so run saveSettings again there.
Technical details
Names used in this script
Open these details when you want to adapt the example or look up an exact service or method name.
Show Apps Script symbols and service pages
Apps Script symbols
Service pages
Keep going
Related tasks, basics, and apps
- Task guide Import data from a web API into Sheets
The script reads Open-Meteo once and replaces only Forecast!A1:C12 after checking the response and the destination. It preserves the source and licence links beside the forecast.
- Task guide Check a website and alert when it is down
An hourly trigger fetches one address. The script remembers the last result in a script property, so a long outage produces one alert instead of one every hour.
- Object reference Properties
Properties store key and value text pairs between runs with getProperty() and setProperty(). PropertiesService.getScriptProperties() is shared across the project, user properties are per-person, and document properties are per-file.
- Basics Google Apps Script quotas and limits
Google caps how long one run may take and how much your scripts may do in a day. Knowing the caps changes how you write anything that touches a lot of rows.
- Google app Script utilities
UrlFetchApp, PropertiesService, and LockService work across Google apps to call HTTP endpoints, store key-value settings, and guard shared resources.