14

I'm facing this issue while I'm running the script. one day before if was working fine for me. I did clear all the cache of chrome browser and I tried another laptop also but the issue is as it is. please help me to resolve the issue.

The code I'm running is:

function onOpen(e) {
  var menu = SpreadsheetApp.getUi().createMenu('Reporting Tools');
  menu.addItem('Create Unit Scorecards', 'HSIPScorecard2021CountryScripts.createInputSheets');
  menu.addItem('Notify Unit H&S Heads', 'HSIPScorecard2021CountryScripts.sendNotifications');
  menu.addItem('Consolidate Unit Data', 'HSIPScorecard2021CountryScripts.Consolidate');
  menu.addToUi();
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
Dheeraj Parikh
  • 141
  • 1
  • 3
  • is this intended to be an addon? – Baby_Boy Jan 07 '21 at 18:14
  • Is this `HSIPScorecard2021CountryScripts` the name of your library and has it been installed properly? – Cooper Jan 07 '21 at 19:16
  • 1
    Related bug report on the Google Apps Script issue tracker: [Using a lib that has view permissions gives "a server error occurred while reading from storage. Error code NOT_FOUND."](https://issuetracker.google.com/issues/183634726) – Rubén May 19 '22 at 15:16

5 Answers5

25

I just ran into the same problem last week. After wasting a few day's time, I found it was caused by a reference to a library using development mode. Change it to a deployment version solved that.

dodopok
  • 868
  • 14
  • 22
rugbbyli
  • 251
  • 2
  • 3
  • 2
    For future viewers: This appears to still be a solution as of August 2021. Certainly, I had the same issue described by the OP and this answer resolved it directly. – Paul Aug 11 '21 at 08:58
  • Update April 2023; you can also overcome this by using an installed onOpen() trigger in the library. – Felix Weelix Apr 11 '23 at 20:15
1

Assuming that the name of the library is correct you can write that like this:

function onOpen(e) {
      SpreadsheetApp.getUi().createMenu('Reporting Tools')
      .addItem('Create Unit Scorecards', 'HSIPScorecard2021CountryScripts.createInputSheets');
      .addItem('Notify Unit H&S Heads', 'HSIPScorecard2021CountryScripts.sendNotifications');
      .addItem('Consolidate Unit Data', 'HSIPScorecard2021CountryScripts.Consolidate');
      .addToUi();
    }
Cooper
  • 59,616
  • 6
  • 23
  • 54
0

There are two things that need to be checked in order to fix this issue.

  1. The Library reference should link to the Deployment Version and not to the Development Mode.
  2. The Library file should not be restricted in case you are sharing the copy of the original file with somebody else.
Sohail Malik
  • 305
  • 1
  • 2
  • 12
0

I had the same error... It appeared that the library (HSIPScorecard2021CountryScripts in your case) had a reference to another library (BasicTools). From the account that owned both, it worked. However, from any other account, that error appeared. Even if Edit permission was given.

The solution was to move the functions from BasicTools to HSIPScorecard2021CountryScripts (and fix the functions calls).

So, in short, one more solution to try is to make sure the library you are using doesn't use any other libraries.

Abdallah El-Yaddak
  • 440
  • 1
  • 9
  • 18
0

Using an installable trigger in the parent library (instead of onOpen() in the dependent script) also fixes this issue.

ScriptApp.newTrigger('exported.createDefaultMenuAndAddToUI')
  .forSpreadsheet(SpreadsheetApp.getActive())
  .onOpen()
  .create(); 

It will give you a new problem in that the menu item actions are outside of the dependent library scope. I manage referencing things that need to be accessed by both the library and its dependent scripts like this:

function getExports () {
  return {  
    /* TRIGGERS */
    hourlyCronTask, 
    createDefaultMenuAndAddToUI,
    /* MENU ITEMS */
    actionInitialHelp,
    ...
  };
}

const exported = getExports();

Then in dependent script Code.js

const exported = MyParentLibrary.getExports();

These need to be defined in a hoistable function rather than a constant since only these are exposed to dependent scripts.

Felix Weelix
  • 352
  • 3
  • 7