I have basically modified a UI that comes on the UI google documentation to adapt it to my needs. I have a panel that gets info from user, then it is supposed to replace some words in a template and at the end send an email. This is what I have written so far. Everything works great just the part where it makes the replace is not working which(var Time = setValue(e.parameter.userName) but I am not sure if is correct or I should use something different. I tried using var Time = emailTemplate.replace(“TIME”,e.parameter.userName)); but I get reference error, e is not defined and is not running. Any help would be appreciated.
function onOpen() {
var subMenus = [{name:"test", functionName: "doGet"}];
SpreadsheetApp.getActiveSpreadsheet().addMenu("texts", subMenus);}
function doGet() {
var doc = SpreadsheetApp.openById("SP ID");
var app = UiApp.createApplication().setTitle('TITLE1');
var grid = app.createGrid(10, 10);
grid.setWidget(0, 0, app.createLabel('Time PST'));
grid.setWidget(0, 1, app.createTextBox().setName('Time'));
grid.setWidget(1, 0, app.createLabel('Minutes have passed'));
grid.setWidget(1, 1, app.createTextBox().setName('Minutes'));
grid.setWidget(2, 0, app.createLabel('Enter Name'));
grid.setWidget(2, 1, app.createTextBox().setName('Name'));
// Create a vertical panel..
var panel = app.createVerticalPanel();
// ...and add the grid to the panel
panel.add(grid);
var button = app.createButton('Submit');
var handler = app.createServerHandler('b');
handler.addCallbackElement(grid);
button.addClickHandler(handler);
// Add the button to the panel and the panel to the application, then display the application app
panel.add(button);
app.add(panel);
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
}
function b() {
var doc = SpreadsheetApp.openById("SP ID");
var emailTemplate = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A1").getValue() ;
var address = "albdominguez25@gmail.com";
var Time = setValue(e.parameter.Time);
var emailSubject = "Subject";
emailTemplate = emailTemplate.replace("TIME",Time);
MailApp.sendEmail(address, emailSubject, emailTemplate);
Browser.msgBox("Your Email has been sent!");
// Clean up - get the UiInstance object, close it, and return
var app = UiApp.getActiveApplication();
app.close();
// The following line is REQUIRED for the widget to actually close.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
}
I’m assuming you want to change the text in the TextBox ‘Time’ when the button is clicked.
First, you need to set an id on the text box
Then, you need to use setText() on the TextBox to change the value