When I'm on my Google Sheet, I have a checkbox that triggers a Modal Dialog box when selected via an onEdit function. I've added in the trigger on the project and when the checkbox is selected, the dialog shows just fine and I do not see an error.
However, in the Executions log, it lists the execution twice, and one of them fails and the other processes just fine. I checked in the project Overview, and the listed scope is present, so I'm not sure what the issue is. Here is the onEdit function and the function that has the Modal Dialog box.
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var ui = SpreadsheetApp.getUi();
var sheet = ss.getName();
var cell = e.range;
var row = cell.getRow();
var col = cell.getColumn();
var val = cell.getValue();
if (sheet == "Emails" && col == 5 && row == 2) {
addEmailValidations(ss,ui);
} else if (sheet == "Emails" && col == 10 && row != 1 && val == true) {
previewEmail(ss,ui,row); //Row 24 in error message below
} else {
}
}
function previewEmail(ss,ui,row) {
console.log('previewemail start');
var sendCheck = ss.getRange(row,8).getValue();
var emailTemp = ss.getRange(row,9).getValue();
if (emailTemp == "") {
console.log('Stopped process: template not selected.');
ui.alert("Error","Please select an Email Template.",ui.ButtonSet.OK);
} else {
if (sendCheck == false) {
console.log('send was false');
ss.getRange(row,8).setValue(true);
SpreadsheetApp.flush();
} else {
}
var subject = ss.getRange(row,14).getValue();
var body = ss.getRange(row,15).getValue();
var rec = ss.getRange(row,16).getValue();
var htmlOut = HtmlService
.createHtmlOutput('<font face="Arial"><b>To:</b> ' + rec + '<br /><b>Subject:</b> ' + subject + '<br /><hr><br />' + body + '</font>')
.setWidth(800)
.setHeight(450);
ui.showModalDialog(htmlOut,'Email Preview'); //Row 113 in error message below
ss.getRange(row,10).setValue(false);
}
}
From the user perspective, the dialog box shows just fine, but here is the execution log:
Exception: You do not have permission to call Ui.showModalDialog.
Required permissions:
https://www.googleapis.com/auth/script.container.ui
at previewEmail(Code:113:8)
at onEdit(Code:24:5)
But when I go into the Overview, the correct scope is listed:
Is there something weird that I've done with my onEdit trigger that's causing this to happen? And yes, I've gone into the Triggers section and added in a trigger to run this function on edit.
Any help would be greatly appreciated - thanks!