'Show Alert Popup when cell selection is changed (onSelectionChange)
I am trying to show an alert popup when cell selection is changed, using the new trigger onSelectionChange
.
For some reason it is not showing any alerts.
Am i doing something wrong or alerts does not work with this trigger?
function onSelectionChange(e) {
showAlert();
}
function showAlert() {
var ui = SpreadsheetApp.getUi();
var result = ui.alert(
'ALERT!',
'ALERT MESSAGE.',
ui.ButtonSet.OK);
}
I also tried that way:
function onSelectionChange(e) {
var ui = SpreadsheetApp.getUi();
var result = ui.alert(
'ALERT!',
'ALERT MESSAGE.',
ui.ButtonSet.OK);
}
Solution 1:[1]
I created a script to test different ways to show a "pop up" in Google Apps Script. In both runtimes, only the one that use the HTML Service throw an error. The test was done using Chrome, a G Suite account, only signed in in one account.
Here is the code of the referred script:
function onSelectionChange(e) {
var message = e.range.getA1Notation();
switch(e.range.columnStart){
case 1:
alert(message);
break;
case 2:
toast(message);
break;
case 3:
msgBox(message);
break;
case 4:
dialog(message);
break;
case 5:
alertWithButton(message);
break;
default:
console.info(message);
}
}
function alert(message){
SpreadsheetApp.getUi().alert(message);
}
function toast(message){
SpreadsheetApp.getActiveSpreadsheet().toast(message);
}
function msgBox(message){
Browser.msgBox(message);
}
function dialog(message){
SpreadsheetApp.getUi().showModalDialog(
HtmlService.createHtmlOutput(message),
'Alert'
)
}
function alertWithButton(message){
var ui = SpreadsheetApp.getUi();
ui.alert(message, ui.ButtonSet.OK);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rubén |