I have a spreadsheet which launches a modal dialog form to get information. Some client side validation for required fields but also server side validation: does the input data already exist. Logger.log has not worked for 4 days now so I am using alert. In the server side validation someone wrote you cannot use getActive as you are not in the spreadsheet but in the dialog form. So:
function onLoad() {
const ui = SpreadsheetApp.getUi();
const ssId = SpreadsheetApp.getActive().getId();
PropertiesService.getScriptProperties().setProperty('ssId', ssId);
and in the server side validation - this does not allow me to get to UI in order to send an alert
function addMbrCode(myAddForm) {
const ssId = PropertiesService.getScriptProperties().getProperty('ssId');
var ssQ = SpreadsheetApp.openById("[ssId]");
var ss = SpreadsheetApp.setActiveSpreadsheet(ssQ);
ss.alert("Beginning addMbrCode" );
The spreadsheet UI can't be accessed in this context. "open" does not mean "show in browser", it means "open for read and write"... – @Serge insas
So is it possible to issue an alert in this situation?
Partial answer - I wrote my 'logging' to a Google doc on MyDrive.
/**
* this code is run from the javascript in the html dialog
*/
function addMbrCode(myAddForm) {
// cannot access UI to issue alerts on Spreadsheet in this context
var formattedDate = Utilities.formatDate(new Date(), "GMT", "MM-dd-yyyy HH:mm:ss");
var myLog = DocumentApp.create('addMbrCode ' + formattedDate );
var logId = myLog.getId();
var body = DocumentApp.openById(logId).getBody();
var paragraph;
console.log("Beginning addMbrCode" );
paragraph = body.appendParagraph('Beginning addMbrCode.');
. . .
paragraph = body.appendParagraph('end addMbrCode returning: ' + retCd );
myLog.saveAndClose();
return retCd;
}
However running this server side validation from the javascript in the browser appears to not allow meaningful interaction with my spreadsheet despite @Serge insas comment that "it means "open for read and write". This is probably a new question. I will post separately.