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!
Answer
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.
In order to use the
prompt()
method within theonOpen()
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 asshowModalDialog()
.
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
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM