Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:25:22+00:00 2026-06-06T15:25:22+00:00

I have read some of the basic Google Apps Script documentation/tutorials. I have not

  • 0

I have read some of the basic Google Apps Script documentation/tutorials. I have not found any explanation of the “scope” of code execution.

Here is what I understand so far:

 All code consists of one or more statements
 All statements must (?) be contained in a "function"
     (a slight different from non-google javascript? - is this a false assumption?) 
 All functions reside in a container called a "file"
 Each "file" is part of a "project" container (or library)
 Each project container is stored in a "spreadsheet" container.

These are the “physical” (edit access) boundaries.

My question is what is the “logical” boundaries of statements
during execution?

I started by assuming all variables/objects were global in scope,
similar to the way that JavaScript operates in a web-page. I did not think that
“edit access” containers limited the scope of variable/object definitions.
I was wrong.

I thought that a “library” structure is similar to a PHP “include” operation.
By that I thought it would save me from having to copy the same set of
code into every application (spreadsheet container), in which I needed to
use the already “tested” code. I assumed the resources available to the
included project were the same as those available to the including
project common resources). In short, I was wrong. The “properties” were stored in the defining spreadsheet, and are considered to be “owned” by the containing project.

From playing with it, I now understand that the “project key” just adds
a new “namespace” to the spreadsheet container. What happens in each
namespace remains in that namespace. The only (simplest) communication
between the namespaces is via function parameters and return value.

In particular, User, and Project properties are scoped to and remain in
their containing spreadsheet document. Each project within the spreadsheet
document has separate set of User and Project properties.

The same project/library name can appear in multiple spreadsheet files
and are totally independent.

Is this documented somewhere? And are there other things I need to know
about scoping (communication across threads from different applications
sharing the same project/library?

Also, if a function passes back a reference to an object defined in the
library scope, will it persist in the calling’s project? Can I pass/return
a variable that points to a project’s UserProperties “sevice” object and have access
to that data in another project?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:25:23+00:00Added an answer on June 6, 2026 at 3:25 pm

    This is documented towards the end of the User Guide in Libraries:
    https://developers.google.com/apps-script/guide_libraries

    When deciding how to scope things, we tried to think really hard about the most common use cases, and try to reduce surprise as much as possible, but we weren’t perfect.

    Regarding your question on whether you can use parameter-passing to share ScriptProperties objects between the library and the project, that’s currently not possible. You can always expose getters/setters for particular properties.

    If you have an interesting use case in mind which is impossible to achieve without the requested behavior, please file a bug in our issue tracker. Thanks!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read some posts on here about not mixing parameters when passing into
I have just switched from svn to mercurial and have read some tutorials about
I have read through some tutorials about javascript prototypal inheritance patterns but I am
I have some basic c# code which connects to a database and prints out
I've started to do some basic network programming. I have read/written my own programs
I have read some tutorials for bezier curve such as this one http://www.codeproject.com/KB/recipes/BezirCurves.aspx .
I have read some where that ruby fork are COW friendly ok here the
I have read some posts, but I still find it difficult to solve this.
I have read some posts about this topic and the answers are comet, reverse
I have read some articles on POCO in the enttity framework but still don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.