1

After refreshing the shared spreadsheet, onOpen is not running to other users who also have access.

But the owner is being able to run the codes and script.

Code.gs

function onOpen(e) {
    test();
  SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp, or FormApp.
      .createMenu('Custom Menu')
      .addItem('First item', 'menuItem1')
      .addToUi();
    SpreadsheetApp.getUi() // Or DocumentApp, SlidesApp, or FormApp.
        .createMenu('Custom Menu').addItem('Test', 'test').addToUi();
};

function test() {
    var ui = SpreadsheetApp.getUi(); // Same variations.
    var result = ui.prompt('Spreadsheet Restriction', 'Enter password:', ui.ButtonSet.OK);
    // Process the user's response.
    var button = result.getSelectedButton();
    var text = result.getResponseText();
    if (button == ui.Button.OK) {
        // User clicked "OK".
    } else if (button == ui.Button.CLOSE) {
        // User clicked X in the title bar.
        ui.alert('Spreadsheet is protected.');
        test();
    }
};
function myFunction() {

}

Already shared the access spreadsheet and script to other users but they can't still see it is working. Appreciate your help guys... Thanks!

Bry
  • 628
  • 1
  • 6
  • 17

1 Answers1

1
  1. The users of your Sheet/script must have edit access on the Sheets document in order for the onOpen() trigger to be executed. From the documentation:

    They do not run if a file is opened in read-only (view or comment) mode.

  2. In order to use the prompt() method within the onOpen() function, you must use an installable trigger. Furthermore, the trigger must be set up by the user who is going to use it. The same also applies to other functions of the UI class such as showModalDialog().

This strict rules are most likely enforced in order to protect the end user of potential scams. If you are interested in protecting your Sheets document with password, I suggest you check out other solutions such as this one,

Reference

Community
  • 1
  • 1
carlesgg97
  • 4,184
  • 1
  • 8
  • 24