Let's say I have this function:
function alertar(userEmail) {
var doc = DocumentApp.getActiveDocument();
// Get the URL of the document.
var url = doc.getUrl();
// Send yourself an email with a link to the document.
var u = Session.getActiveUser();
ui.alert('it worked');
GmailApp.sendEmail(userEmail, "assunto", "hey, click here" + url);
}
And then I created menus as follows:
var editors = DocumentApp.getActiveDocument().getEditors();
var m = ui.createMenu('uPaPoPe Actions');
var subMenu = ui.createMenu('Escritores');
for (var i=0;i<editors.length;i++)
{
subMenu.addItem(editors[i].getEmail(), 'function() {alertar("'+editors[i].getEmail()+'");}'); //line with problem
}
How do I pass parameters to a function that requires them from a google apps script menu item? Doing any of the following constructions is not valid:
subMenu.addItem(editors[i].getEmail(), 'function() {alertar("'+editors[i].getEmail()+'");}');
subMenu.addItem(editors[i].getEmail(), 'alertar("'+editors[i].getEmail()+'");');
This is allowed:
subMenu.addItem(editors[i].getEmail(), 'alertar');
But the latter does not allow me to pass the editor's email as parameter.