Skip to content

Task guide

Store settings with PropertiesService

Keep a setting such as an email address out of your code and change it without editing the script. The project stores it as a script property that every run can read.

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.
  • Find Project Settings, the gear icon in the left sidebar of the editor. 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

Change these values

Make the code yours before you run it.
Recipient property
REPORT_RECIPIENT

The name the script looks up. Capital letters with underscores make property names easy to spot in the code.

Recipient value
you@example.com

The example address saved under that name. Replace it with the address you actually use.

Title property
REPORT_TITLE

The name of the second setting, so you can see how several values are saved at once.

Title value
Weekly report

The example title saved under that name.

2 · Review before running

What the script can access and change

Permissions you approve

  • Nothing to approve. PropertiesService and Logger need no permission, so Google does not show the authorization dialog for these two functions.
  • The code only saves and reads two values stored with this Apps Script project. It does not touch your Sheets, Gmail, or Drive.

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.

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.

Code.gs
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

Follow these steps in order

  1. Paste both functions and run showSettings first

    Paste both functions over the starter code and save. Choose showSettings in the function dropdown above the code, then click Run. Nothing is saved yet, so the run stops with "REPORT_RECIPIENT is not set. Run saveSettings once, or add the property in Project Settings." This test changes nothing.

  2. Save the settings once

    Choose saveSettings and click Run. The Execution log shows the two saved values. Run this function again only when you want to overwrite the values from code.

  3. Read them back

    Choose showSettings and click Run again. The Execution log now prints both values. Every later run reads the saved values, so you can change a value without editing the code.

  4. Edit a value without touching the code

    Open Project Settings, the gear icon in the left sidebar, and scroll to Script Properties. Click Edit script properties, change the value of REPORT_RECIPIENT, and click Save script properties. Run showSettings once more to see the new value.

  5. 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 stops with "REPORT_RECIPIENT is not set. Run saveSettings once, or add the property in Project Settings."
Run saveSettings, or add the name and value by hand under Project Settings, Script Properties. The name has no value yet.
A saved number behaves like text.
Wrap the value in Number(...) when you need to do arithmetic with it. Property values are always text.
A colleague can see a value you thought was private.
Keep anything private out of the project. 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.
The property is gone after copying the Sheet or making a new project.
Run saveSettings again in the new project. Properties belong to one script project, so a copy of the Sheet or a new project starts with an empty list.

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