Cannot dynamically update UI Grid Class Google Apps Script - google-apps-script

I've been trying to get my UIAPP grid to dynamically add objects based on a button insert button but cannot seem to do so. I don't know why this isn't working. Any help would be greatly appreciated.
function trackColumns()
{
var app = UiApp.createApplication().setWidth(500).setHeight(360).setTitle('Step 1: Select Information to Track');
var panel = app.createVerticalPanel().setId("settingsPanel");
var headerpanel = app.createVerticalPanel().setId("headerPanel").setStyleAttribute("background", "silver").setWidth(500);
var columnPanel = app.createVerticalPanel();
var mainGrid = app.createGrid(5, 1).setId("mainGrid");
var columnGrid =app.createGrid(1,1).setId("columnGrid");
var columnspanel = app.createHorizontalPanel().setId("columnspanel");
var columnname = app.createTextBox().setText("Name");
columnspanel.add(columnname);
var addcolumnspanel = app.createHorizontalPanel().setId("addcolumnspanel");
var addbuttonhandler = app.createServerHandler("addcolumn");
addbuttonhandler.addCallbackElement(columnGrid);
var addbutton = app.createButton().setId("btnaddcolumn").setText("Add another column").addClickHandler(addbuttonhandler);
addcolumnspanel.add(addbutton);
columnGrid.setWidget(0, 0, columnspanel);
mainGrid.setWidget(1, 0, columnGrid);
mainGrid.setWidget(2, 0, addcolumnspanel);
panel.add(mainGrid);
app.add(panel);
ss.show(app);
return app;
}
function trackster_addcolumn(e) {
var app = UiApp.getActiveApplication();
var columnspanel = app.createHorizontalPanel().setId("columnspanel");
var columnname = app.createTextBox().setText("Name");
var columntype = app.createListBox();
columntype.addItem("Text");
columntype.addItem("DropDown");
columntype.addItem("Date");
columntype.addItem("Number");
columnspanel.add(columnname);
columnspanel.add(columntype);
var columngrid = e;
columngrid.setWidget(3,0,columnspanel);
return app;
}

From what I can tell...
Would need to initialize this grid for 4 rows if you're wanting to set some thing in (3,0) later in the server function.
var columnGrid =app.createGrid(1,1).setId("columnGrid"); >> var columnGrid =app.createGrid(4,1).setId("columnGrid");
Server function name just needs to match what's in the createServerHandler()...
function trackster_addcolumn(e) >> function addcolumn(e)
e has the values of all the widgets passed through to the server function, not the actual widgets themselves. To get grid...
var columngrid = e; >> var columngrid = app.getElementById('columngrid');

Related

GAS e.parameter undefined, uploadWidget won't setName

I'm working on an answer for another question found here. I have modified a different tutorial script from here, but I'm having an issue that the e.parameter for the fileUploadWidget will not accept a .setName() change. No matter what I do with setName, it continues to show the "name" as FileUpload, and won't pass the e.parameter.'file'+numRows on to the uploadFiles(e) (formerly doPost(e)). The folderName parameter will come through, but numRows is coming through as NaN, and the file+numRows is coming through undefined. What is going on here/What am I missing? I've been through tons of solutions on and off SO, but can't seem to figure out where this has gone wrong. Maybe a fresh set of eyes with more experience can see what I'm doing wrong.
You can find the example of this code in action here
//modified from script found here http://www.googleappsscript.org/miscellaneous/creating-form-elements-dynamically-using-google-apps-script-gas
function doGet() {
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var formPanel = app.createFormPanel();
var folderLabel = app.createLabel('Folder Name (temp placeholder to remember to use .getFolderById(folderId) to place in specific folder)');
var folderNameTextBox = app.createTextBox().setId('folderName').setName('folderName');
var filesLabel = app.createLabel('Add Files to Upload');
var table = app.createFlexTable().setId('table').setTag('0'); //Here tag will count the number of members
//Write the header for the table
var headerArray = ['File(s)'];
for(var i=0; i<headerArray.length; i++){
table.setWidget(0, i, app.createLabel(headerArray[i]));
}
//Add the first row of form elelments to input Member information
addMemebrRow(app);
//Add a button to submit the info
var button = app.createSubmitButton('Upload File(s)');
var handler = app.createServerHandler('uploadFiles');
handler.addCallbackElement(panel);
button.addClickHandler(handler);
panel.add(folderLabel)
.add(folderNameTextBox)
.add(filesLabel)
.add(table)
.add(button);
formPanel.add(panel);
app.add(formPanel);
return app;
}
function addMemebrRow(app){
var table = app.getElementById('table');
var tag = parseInt(table.getTag());
Logger.log(tag);
var numRows = tag+1;
if(numRows >1){
table.removeCell(numRows-1, 5);
table.removeCell(numRows-1, 4);
}
Logger.log(numRows);
var uploadWidget = app.createFileUpload();
var uploadWidgetName = uploadWidget.setName('file'+numRows);
var uploadWidgetId = uploadWidget.setId('file'+numRows);
Logger.log(uploadWidgetId.getId());
Logger.log(uploadWidgetName);
table.setWidget(numRows, 0, uploadWidget);
table.setTag(numRows.toString());
addButtons(app);
}
function addButtons(app){
var table = app.getElementById('table');
var numRows = parseInt(table.getTag());
//Create handler to add/remove row
var addRemoveRowHandler = app.createServerHandler('_addRemoveRow');
addRemoveRowHandler.addCallbackElement(table);
//Add row button and handler
var addRowBtn = app.createButton('+').setId('addOne').setTitle('Add row');
table.setWidget(numRows, 4, addRowBtn);
addRowBtn.addMouseUpHandler(addRemoveRowHandler);
//remove row button and handler
var removeRowBtn = app.createButton('-').setId('removeOne').setTitle('Remove row');
table.setWidget(numRows, 5, removeRowBtn);
removeRowBtn.addMouseUpHandler(addRemoveRowHandler);
}
function _addRemoveRow(e){
Logger.log(e.parameter.source);
var app = UiApp.getActiveApplication();
var table = app.getElementById('table');
var tag = parseInt(e.parameter.table_tag);
var source = e.parameter.source;
//Logger.log(tag);
if(source == 'addOne'){
table.setTag(tag.toString());
addMemebrRow(app);
}
else if(source == 'removeOne'){
if(tag > 1){
//Dcrement the tag by one
var numRows = tag-1;
table.removeRow(tag);
//Set the new tag of the table
table.setTag(numRows.toString());
//Add buttons in previous row
addButtons(app);
}
}
return app;
}
function uploadFiles(e) {
var foldername = e.parameter.folderName;
Logger.log(foldername);
var numFiles = parseInt(e.parameter.table_tag);
Logger.log(numFiles);
for (var i = 1; i<=numFiles; i++){
Logger.log(i);
var fileBlob = e.parameter['file'+i];
var newFile = DocsList.getFolderById("0B2p9JhtmHqC8Q0lIQk1mMERQTW8").createFile(fileBlob);
}
var app = UiApp.getActiveApplication();
var label = app.createLabel(numFiles +' file(s) uploaded successfully');
app.add(label);
return app;
}
File upload in forms needs a doPost function to work, this is not an option ;)
In such a structure (doGet/doPost) you don't have to define a handler nor a callBackElement, the formPanel is supposed to include all its elements automatically.
So I tried your modified code and still get one major issue with the numFiles value that is on the table tag : I can't get it...
If I replace it with a fixed value then everything works nicely, I get the files in the right folder.
So this answer is not a good answer because it doesn't bring a full solution but at least it reduces its initial scope to that point : how to get this ##!#! numFiles value ?
EDIT : Found the issue : table doesn't support setName method so its value can't be retrieved in the submitHandler. We should use another widget to hold that value.
new working Code below : (I used a textBox as a "hidden" widget for test only, please replace by a hiddenWidget when in production)
function doGet() {
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var formPanel = app.createFormPanel();
var folderLabel = app.createLabel('Folder Name (temp placeholder to remember to use .getFolderById(folderId) to place in specific folder)');
var folderNameTextBox = app.createTextBox().setId('folderName').setName('folderName');
var filesLabel = app.createLabel('Add Files to Upload');
var table = app.createFlexTable().setId('table').setTag('0'); //Here tag will count the number of members
//Write the header for the table
var headerArray = ['File(s)'];
for(var i=0; i<headerArray.length; i++){
table.setWidget(0, i, app.createLabel(headerArray[i]));
}
//Add the first row of form elelments to input Member information
addMemebrRow(app);
var hidden = app.createTextBox().setName('hidden').setId('hidden').setValue(table.getTag());// used to hold the number of files, replace with createHidden()
//Add a button to submit the info
var button = app.createSubmitButton('Upload File(s)');
panel.add(folderLabel)
.add(folderNameTextBox)
.add(filesLabel)
.add(table)
.add(button);
formPanel.add(panel.add(hidden));
app.add(formPanel);
return app;
}
function addMemebrRow(app){
var table = app.getElementById('table');
var tag = Number(table.getTag());
Logger.log('tag='+tag);
var numRows = tag+1;
if(numRows >1){
table.removeCell(numRows-1, 5);
table.removeCell(numRows-1, 4);
}
Logger.log(numRows);
var uploadWidget = app.createFileUpload();
var uploadWidgetName = uploadWidget.setName('file'+numRows);
var uploadWidgetId = uploadWidget.setId('file'+numRows);
Logger.log(uploadWidgetId.getId());
Logger.log(uploadWidgetName);
table.setWidget(numRows, 0, uploadWidget);
table.setTag(numRows);
addButtons(app);
}
function addButtons(app){
var table = app.getElementById('table');
var numRows = Number(table.getTag());
//Create handler to add/remove row
var addRemoveRowHandler = app.createServerHandler('_addRemoveRow');
addRemoveRowHandler.addCallbackElement(table);
//Add row button and handler
var addRowBtn = app.createButton('+').setId('addOne').setTitle('Add row');
table.setWidget(numRows, 4, addRowBtn);
addRowBtn.addMouseUpHandler(addRemoveRowHandler);
//remove row button and handler
var removeRowBtn = app.createButton('-').setId('removeOne').setTitle('Remove row');
table.setWidget(numRows, 5, removeRowBtn);
removeRowBtn.addMouseUpHandler(addRemoveRowHandler);
}
function _addRemoveRow(e){
Logger.log(e.parameter.source);
var app = UiApp.getActiveApplication();
var hidden = app.getElementById('hidden');
var table = app.getElementById('table');
var tag = Number(e.parameter.table_tag);
var source = e.parameter.source;
//Logger.log(tag);
if(source == 'addOne'){
table.setTag(tag.toString());
hidden.setValue(tag+1);
addMemebrRow(app);
}
else if(source == 'removeOne'){
if(tag > 1){
//Dcrement the tag by one
var numRows = tag-1;
table.removeRow(tag);
//Set the new tag of the table
table.setTag(numRows);
hidden.setValue(numRows);
//Add buttons in previous row
addButtons(app);
}
}
return app;
}
function doPost(e) {
var foldername = e.parameter.folderName;
Logger.log('foldername = '+foldername);
var numFiles = Number(e.parameter.hidden);
Logger.log('numFiles = '+numFiles);
for (var i = 1; i<=numFiles; i++){
Logger.log(i);
var fileBlob = e.parameter['file'+i];
var newFile = DocsList.getFolderById("0B3qSFd3iikE3QXdubnVoMXlGMkk").createFile(fileBlob);
}
var app = UiApp.getActiveApplication();
var label = app.createLabel(numFiles +' file(s) uploaded successfully');
app.add(label);
return app;
}

Image is loaded after the process completion and remains after that

My code is below. It will accept data from the input text; then it will fetch the recent newest feed from stackoverflow(based in the input) in google spreadsheet.
I have(wanted) set an external gif image to be shown as a progress indicator while fetching of rss feed and its processing is going on.
Problem is: When i remove the commented part; that gif image will never be visible to the user and when that is remained as a comment; that gif image is being loaded by the app after the completion of the process and remained then after.
I want it to be visible only when the process(fetching of rss and processing of it) is going on. So is there any way to make it possible?
function stackoverflow(){
var app =UiApp.createApplication().setHeight(380).setWidth(800);
app.setTitle("Enter tag name");
var mydoc=SpreadsheetApp.getActiveSpreadsheet();
var txtBox = app.createTextBox().setFocus(true).setWidth("150").setId("ticker").setName("ticker");
var mainpanel = app.createHorizontalPanel().setId('mainpanel');
mainpanel.add(txtBox);
var subbtn = app.createButton("Get posts!").setId("tick").setWidth("80");
mainpanel.add(subbtn);
var myloadingimg=app.createImage("http://schedule.msu.edu/img/InProgress.gif").setHeight("26").setWidth("26").setId("loadingimg");
mainpanel.add(myloadingimg.setVisible(false));
app.add(mainpanel);
var panel = app.createVerticalPanel().setId('panel');
var submitHandler = app.createServerHandler("clicker").addCallbackElement(mainpanel);
subbtn.addClickHandler(submitHandler);
app.add(panel);
mydoc.show(app);
}
function clicker(e){
var app = UiApp.getActiveApplication();
var txtBox = app.getElementById("ticker");
app.getElementById("loadingimg").setVisible(true);
var panel=app.getElementById("panel");
app.remove(1);
var panel = app.createVerticalPanel().setId('panel');
var stackurl = "http://stackoverflow.com/feeds/tag?tagnames="+e.parameter.ticker+"&sort=newest";
var stackXML = UrlFetchApp.fetch(stackurl).getContentText();
var stackDOC = Xml.parse(stackXML, false);
var stackentry = stackDOC.getElement().getElements('entry');
for (var i = 0; i < stackentry.length; i++) {
var result = stackentry[i];
panel.add(app.createHTML("<br><b>Post Title: </b>"+ result.getElement('title').getText()+"<br>"));
panel.add(app.createAnchor('', '') .setText("Post URL").setHref(result.getElement('link').getAttribute('href').getValue()));
panel.add(app.createHTML("<br>"));
}
var scroll = app.createScrollPanel().setPixelSize(760, 280);
scroll.add(panel);
app.add(scroll);
//app.getElementById("loadingimg").setVisible(false);
return app;
}
function onOpen()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name:'stackoverflow',functionName:'stackoverflow'});
ss.addMenu("f2", menuEntries);
}
You can make use of clientHandlers which are meant for precisely such cases.
function stackoverflow(){
...
var clientHandler = app.createClientHandler().forTargets(myloadingimg).setVisible(true);
var submitHandler = app.createServerHandler("clicker").addCallbackElement(mainpanel);
subbtn.addClickHandler(submitHandler).addClickHandler(clientHandler);
...
}
function clicker(e){
var app = UiApp.getActiveApplication();
....
app.getElementById("loadingimg").setVisible(false);
return app;
}

Not replacing e.parameter

I created this script to be able to send an email after a grid has been filled with information. Before the email is sent, another display comes in an warns the user to continue only if the information is correct. At the end the script sends an email to me, with the info entered by the user. The problem is here, when I received the email, the fields that the script is suppose to replace are shown as undefined and no info is there. Any ideas on what is wrong here??
Thank you!
function runmyapp() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('Title 1');
var grid = app.createGrid(4, 5);
grid.setWidget(0, 0, app.createLabel('Time '));
grid.setWidget(0, 1, app.createTextBox().setName('Time'));
grid.setWidget(1, 0, app.createLabel('Minutes'));
grid.setWidget(1, 1, app.createTextBox().setName('Minutes'));
grid.setWidget(2, 0, app.createLabel('Enter Name'));
grid.setWidget(2, 1, app.createTextBox().setName('Name'));
grid.setWidget(3, 0, app.createLabel('Email'));
grid.setWidget(3, 1, app.createTextBox().setName('email'));
var panel = app.createVerticalPanel();
panel.add(grid);
var button = app.createButton('Submit').setId("button");
var handler2 = app.createServerHandler('dis');
handler2.addCallbackElement(grid);
button.addClickHandler(handler2);
var handler = app.createServerHandler('disc');
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 dis(e){
var app = UiApp.getActiveApplication();
app.getElementById("button").setText("Request is in process, please wait!").setEnabled(false);
return app;
};
function disc(e){
var app = UiApp.getActiveApplication();
var html1 = app.add(app.createHTML("<p><p>Hello Expert,</p>"+
"<p>By clicking OK you agree that your information is correct</p>");
var button = app.createButton('Ok').setId("button");
app.add(button);
var handler2 = app.createServerHandler('gsnot');
button.addClickHandler(handler2);
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
return app;}
function gsnot(e) {
var advancedArgs = {bcc:e.parameter.email};
var emailSubject = "Subject";
var address ="albdominguez25#gmail.com";
var emailTemplate =SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Templates").getRange("A1").getValue( ) ;
emailTemplate = emailTemplate.replace("TIME", e.parameter.Times).replace("MIN", e.parameter.Minutes).replace("EXP", e.parameter.Name);
MailApp.sendEmail(address, emailSubject, emailTemplate, advancedArgs);
Browser.msgBox("Your Email has been sent!");
var app = UiApp.getActiveApplication();
app.close();
// The following line is REQUIRED for the widget to actually close.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
}
To make a widget value show on your e.parameter you need to add it (or a parent panel) as a callback element on the handler. Like this:
function runmyapp() {
//...
var grid = app.createGrid(4, 5).setId('grid');
//...
}
function disc(e){
//...
var grid = app.getElementById('grid');
var handler2 = app.createServerHandler('gsnot').addCallbackElement(grid);
//...
}
Keep Henrique's answer as best one please.
You can try to change your disc(e) function like this :
function disc(e){
var app = UiApp.getActiveApplication();
var html1 = app.add(app.createHTML("<p><p>Hello Expert,</p>"+
"<p>By clicking OK you agree that your information is correct</p>"));
var grid = app.getElementById('grid')
var button = app.createButton('Ok').setId("button");
app.add(button);
var handler3 = app.createServerHandler('gsnot');// use a different name to avoid confusion
handler3.addCallbackElement(grid);
button.addClickHandler(handler3);
return app;}
And, also, there is a typo in your code in this line :
emailTemplate = emailTemplate.replace("TIME", e.parameter.Times).replace("MIN", e.parameter.Minutes).replace("EXP", e.parameter.Name);
Time has no 's' at the end in the original name ! ;)
and, last point, if I where you I wouldn't call show(app) in disc so the UI would keep the data validation while confirming... (but that's a matter of choice ;-)

Replace formula of a cell with script

I am trying to replace some part of a formula in cell D3 of a spreadsheet, but I can't seem to do it. The formula in D3 is very long, but I only need to replace what would be searchtext variable and replace it with replacetext variable. Any ideas? Here's my code.
function dashboards(){
var ss1 = SpreadsheetApp.getActiveSpreadsheet();
var origSheet1 = ss1.getSheetByName('Daily');
var searchtext = Browser.inputBox("Enter search text");
var replacetext = Browser.inputBox("Enter replace text");
var form = origSheet1.getRange("D3").getFormulaR1C1();
form.indexof(searchtext);
var updated = form.replace(searchtext, replacetext);
form.setFormula(updated);}
You're not far off. The problem is that form, the below, is a String, not a reference to your Range.
var form = origSheet1.getRange("D3").getFormulaR1C1();
You can see this by inserting
Logger.log(form + "; type: " + typeof form); //String
after that line and checking the log in the Script Editor.
You just need to change
form.setFormula(updated);
to
origSheet1.getRange("D3").setFormulaR1C1(updated);
to update the actual range.
Copy the code below and run it via Script Manager or a menu item.
It operates on whatever the selected range is, whether it's a single cell or extends over multiple rows & columns.
It pops up a toast message to tell you when the procedure has finished but it leaves the UiInstance open in case you want to do more replacing.
You can keep it open and perform multiple search/replace in formulas on multiple selections or the same search on different sheets.
function handySRF() { // script composed by ailish#ahrosters.com
var ss = SpreadsheetApp.getActive();
var app = UiApp.createApplication().setHeight(200).setWidth(270).setTitle('Search and Replace In Formulas');
var panel = app.createAbsolutePanel().setId('panel').setHeight(198).setWidth(268)
.setStyleAttribute('background', 'lightCyan');
var lblSearch = app.createLabel('Search for:').setId('lblSearch');
var txtSearch = app.createTextBox().setId('txtSearch').setName('txtSearch');
var lblReplace = app.createLabel('Replace with:').setId('lblReplace');
var txtReplace = app.createTextBox().setId('txtReplace').setName('txtReplace');
var handler = app.createServerHandler('btnStartSearch');
var btnStartSearch = app.createButton('Start Search').addClickHandler(handler)
.setStyleAttribute('background', 'lightGreen');
handler.addCallbackElement(panel);
var handler2 = app.createServerHandler('btnCloseWindow');
var btnCloseWindow = app.createButton('Close Window').addClickHandler(handler2)
.setStyleAttribute('background', 'lightYellow');
handler2.addCallbackElement(panel);
panel.add(lblSearch, 10, 6)
panel.add(txtSearch, 10, 33)
panel.add(lblReplace, 10, 75)
panel.add(txtReplace, 10, 100)
panel.add(btnStartSearch, 10, 151)
panel.add(btnCloseWindow, 130, 151)
app.add(panel);
ss.show(app);
};
function btnStartSearch(e) {
var ss = SpreadsheetApp.getActive();
var app = UiApp.getActiveApplication();
var search = e.parameter.txtSearch;
var replace = e.parameter.txtReplace;
var rows = ss.getActiveSelection();
var numRows = rows.getNumRows();
var formulas = rows.getFormulas();
var newFormulas = [];
for (var i = 0; i <= numRows - 1; i++) {
var oldData = formulas[i];
var newData = [];
for (var j=0; j<oldData.length; ++j) {
var item = oldData[j].replace(new RegExp(search, "g"), replace);
newData.push(item);
}
newFormulas.push(newData);
}
rows.setFormulas(newFormulas);
var str = 'Finished replacing ' + search + ' with ' + replace;
ss.toast(str, '', 2);
};
function btnCloseWindow(e) {
var ss = SpreadsheetApp.getActive();
var app = UiApp.getActiveApplication();
app.close();
return app;
};

Cannot read property "parameter" from undefined error with Logger.log

I am getting "TypeError: Cannot read property "parameter" from undefined." when trying to log e.parameter properties. (I inserted the following lines in the contactMe() function)
Logger.log(e.parameter.textBox);
Logger.log(e.parameter);
The script otherwise works fine, any idea?
function doGet() {
var app = UiApp.createApplication();
var mainPanel = app.createVerticalPanel().setId('mainPanel');
app.add(mainPanel);
mainPanel.add(app.createLabel('Enter your email to sign up'));
var form = app.createHorizontalPanel();
mainPanel.add(form);
var email = app.createTextBox().setName('textBox').setId('textBox');
form.add(email);
var button = app.createButton('Sign up');
form.add(button);
var info = app.createLabel().setVisible(true).setId('info');
mainPanel.add(info);
//handler
var handler = app.createServerHandler('contactMe').addCallbackElement(mainPanel);
button.addClickHandler(handler);
return app;
}
function contactMe(e){
var app = UiApp.getActiveApplication();
Logger.log("testing");
Logger.log(e.parameter);
Logger.log(e.parameter.textBox);
app.getElementById('textBox').setValue('').setStyleAttribute("color", "black");
app.getElementById('info').setText('Thank you!').setStyleAttribute("color", "black");
var ss = SpreadsheetApp.openById('0AqKSxC6f0Cc7dF9aT1lUeXFEcnR2eUFYRGs4Y1NiVVE')
.getSheets()[0];
var range = ss.getRange(ss.getLastRow()+1, 1, 1, 2);
var values = [[new Date(),e.parameter.textBox]];
range.setValues(values);
return app;
}
I just tested your exact code (except the sheet stuff) and it works nicely... except that the logger doesn't show anything when called from a handler function but that's a known issue...
I used the label to check the e.parameter value like this :
app.getElementById('info').setText(e.parameter.textBox).setStyleAttribute("color", "black");
A bit out of the box but i think it should work:
function doGet() {
var app = UiApp.createApplication();
var mainPanel = app.createFormPanel;
app.add(mainPanel);
mainPanel.add(app.createLabel('Enter your email to sign up'));
var form = app.createHorizontalPanel();
mainPanel.add(form);
var email = app.createTextBox().setName('textBox').setId('textBox');
form.add(email);
var button = app.createSubmitButton('Sign up');
form.add(button);
var info = app.createLabel().setVisible(true).setId('info');
mainPanel.add(info);
return app;
}
function doPost(e){
var app = UiApp.getActiveApplication();
//Logger wont work in uiApps
//in Form panels the UI is cleared so you want to write a thank you note
app.add(app.createLabel("Thanks"));
var ss = SpreadsheetApp.openById('0AqKSxC6f0Cc7dF9aT1lUeXFEcnR2eUFYRGs4Y1NiVVE')
.getSheets()[0];
var range = ss.getRange(ss.getLastRow()+1, 1, 1, 2);
var values = [[new Date(),e.parameter.textBox]];
range.setValues(values);
return app;
With kind regards,
Thomas van Latum
I just copy pasted your complete code made a spreadsheet and ran it.
It works just perfectly dont forget your } at the end.....