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 8625569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:49:13+00:00 2026-06-12T07:49:13+00:00

I want to outsource all of my code to a library, however I am

  • 0

I want to outsource all of my code to a library, however I am using ScriptProperties to set and get persistent, global variables (like "mode" : "edit" or "data") for every spreadsheet that uses the code.

According to the specifications it is not possible to have a library write to the hosting scripts ScriptProperties: https://developers.google.com/apps-script/guide_libraries#scoping

Script Properties(**): The same instance is visible to all including scripts when created in the library.

** This means that library has its own instance of the resource/feature and that all scripts that use the library share and have access to that same instance.

So this makes it impossible to set globals for every spreadsheet using one single code library.

Is there a workaround or a solution to this shortcoming of Libraries in combination with ScriptProperties?

Thanks and all the best

Mario

  • 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-12T07:49:15+00:00Added an answer on June 12, 2026 at 7:49 am

    Or perhaps coded a little more elegantly, and more reusable…

    Also included functions which are useful when a spreadsheet is used by more than one user, and they each need to have their own settings.

    /**
     *Returns a script property from the library file to a calling script
    
     * @param {string} key The name of the scriptProperty property to return.
    * @return {string} the string value of the key passed
     */
    
    function getLibraryProperty(key) {
      return ScriptProperties.getProperty(key);
    }
    
    /**
     *Returns the appropriate library property for the calling spreadsheet.
     * @param {string} key The name of the scriptProperty property to return.
    * @return {string} the string value for the key passed
    
     */
    
    function getLibPropForSpreadsheet(key){
      return(ScriptProperties.getProperty(setkey_(key).fullKey));
    
    }
    /**
     *Returns the appropriate library property for the calling spreadsheet by user
     * @param {string} key The name of the scriptProperty property to return.
     * @return {Object.<string,string>} Object containing the key, full key, and value
     */
    function getLibPropForSSUser(key){
      return(ScriptProperties.getProperty(setkey_(key).fullUserKey));
    }
    /**
     *Returns the appropriate library property for the calling spreadsheet.
     * @param {string} key The name of the scriptProperty property to return.
     * @return {Object.<string,string>} the string value of the key passed
     */
    function setLibPropForSpreadsheet(key, keyValue)
    {
      return(setLibProp_(key, setkey_(key).fullKey, keyValue));
    }
    
    function setLibPropForSSUser(key, keyValue)
    {
        return(setLibProp_(key, setkey_(key).fullUserKey, keyValue));
    }
    
    function setLibProp_(key, fullKey, keyValue){
      ScriptProperties.setProperty(fullKey,keyValue)
      var theResult = new Object();
      theResult.value = keyValue;
      theResult.key = key;
      theResult.fullKey = fullKey;
      return(theResult);
    } 
    
    function setkey_(key){
    var theCaller = SpreadsheetApp.getActiveSpreadsheet().getId();
     var theUser = Session.getEffectiveUser().getEmail();
     var fullUserKey = theCaller + '-' +theUser+ '-' + key;
     var fullKey = theCaller + '-' + key; 
      var theKeys = new Object();
      theKeys.fullUserKey = fullUserKey;
      theKeys.fullKey = fullKey;
      return(theKeys);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to know why String behaves like value type while using ==. String s1
Want to get current datetime to insert into lastModifiedTime column. I am using MySQL
Want to trigger itemClicked event for a QTreeWidget Item using the following code. connect(aTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(CallM(QTreeWidgetItem*
I want to outsource the design of my Asp.Net Mvc web application. How can
Want to code a key pad for an calculator. What I want to make
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
I want to outsource my application testing. Is there a way to send only
where to begin ? i want to create multiplayer flash games using Union (any
I'm trying to get my head around using QuartzCore to render semi-complex text/gradient/image UITableViewCell
Possible Duplicate: How to outsource a template js to a different file when using

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.