Question

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

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top