简体   繁体   中英

onOpen is not running to other users except to the owner. How to fix this? Google Script GAS

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!

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM