0

i've created simple GUI with a flow panel name and ID main panel, a label name Label1 a textbox name myTextBox and a button with ID getETA.

my aim is if i enter a value in text box and click submit den the value should write in spreadsheet. my problem is the script is returning undefined in spreadsheet not the actual value i've entered.

var app = UiApp.createApplication();
app.setTitle("My Application");
app.add(app.loadComponent("MyGui"));
SpreadsheetApp.getActiveSpreadsheet().show(app);
var clickHandler = app.createServerHandler('clickGetETA');
clickHandler.addCallbackElement(app.getElementById('mainPanel'));
app.getElementById('getETA').addClickHandler(clickHandler);
var doc = SpreadsheetApp.getActive();
doc.show(app);

}

 // this function responds to submit button
function clickGetETA(e) {
var app = UiApp.getActiveApplication();
var textBoxValue = e.parameter.myTextBox;
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = sheet.getLastRow()+1;
var lastCell = sheet.getRange("A"+lastRow);
lastCell.setValue(textBoxValue);
return app.close();

}

I'm new to stackoverflow dont have enough reputations to post image so posting links of images

image1 image2 image3 image4 image5 image6 image7

Serge insas
  • 45,904
  • 7
  • 105
  • 131
suraj
  • 3
  • 3

1 Answers1

0

I see that you defined the clickHandler in the script AND in the GUI builder... that is one too much, that's probably the cause of the issue

Please try to remove the one in the GUI builder and test again, I don't see any other problem in your test ;-)

You could also of course remove the handler in the script but in that case you should add the callbackelement in there too by developing the smal '+' near the handler name and put your panel there.

EDIT : Sorry, there are 2 handlers in the GUI builder, so that is two too much ! you cannot use a single handler with a single name on 2 different handler type (click & key) if you want to have multiple handlers on a button you should define as many handlers you need, each of the type you want, eventually calling the same function but with different variable names.

Edit 2 the line SpreadsheetApp.getActiveSpreadsheet().show(app); in the begining of the main function souldn't be there either, just remove it since you call the spreadsheet later with var doc = SpreadsheetApp.getActive();

Working code with GUI here

EDIT 3 : issue solved by sharing the questioner sheet, the panel name was not correctly written : mainPanel in the script and mainpanel in the GUI ... Aaaah, case sensitiveness ! ;-) (visible in image6)

Serge insas
  • 45,904
  • 7
  • 105
  • 131
  • ... i've removed key handler in GUI and tried still the problem remain same ....returning undefined value... – suraj Aug 27 '12 at 16:56
  • did you remove both handlers in the GUI builder ? – Serge insas Aug 27 '12 at 16:57
  • no i removed only key handler , do u want me to remove click handler as well? – suraj Aug 27 '12 at 16:59
  • i've also removed click handler in GUI and tried ... but the problem remain same.. – suraj Aug 27 '12 at 17:01
  • I reproduced your test and it works, see link https://docs.google.com/spreadsheet/ccc?key=0AnqSFd3iikE3dHkyMkhYY01iV19nUm0zaGJwUEg2X0E – Serge insas Aug 27 '12 at 17:05
  • yes i've checked ur script its working... but mine is still not working....cant figure it out where i going wrong ... https://docs.google.com/a/kezo.in/spreadsheet/ccc?key=0AsS9MOupoFlJdHBuYS1YRGtIVG1pd1ROSDZDaGYtc1E#gid=0 – suraj Aug 27 '12 at 17:21
  • got worked ...thank q 4 help ... i had assigned GUI id for panel as mainpanel n in script as mainPanel...serge insas..corrected it.. and got work.. – suraj Aug 27 '12 at 17:52