I'm trying to create a GUI where user enters homework for the day. On submit, form will send data to Calendar and Spreadsheet.
Apps Script is telling me that 'createServerClickHandler' is deprecated. What other alternatives are there?
Is there anything wrong with my codes?
//Create the GUI form
function doGet() {
var app = UiApp.createApplication().setTitle('Form and Calendar Events');
//Create a penel which holds all the form elelemnts
var panel = app.createVerticalPanel().setId('panel');
//Create the form elelemnts
var startDateLabel = app.createLabel('Homework Start Date:');
var startDate = app.createDateBox().setId('startDate');
var endDateLabel = app.createLabel('Homework End Date:');
var endDate = app.createDateBox().setId('endDate');
var hwTitleLabel = app.createLabel('Homework title:');
var hwTitle = app.createTextBox().setName('hwTitle').setId('hwTitle');
var hwDetailLabel = app.createLabel('Homework Details:');
var hwDetails = app.createTextArea()
.setSize('200', '100').setId('hwDetail').setName('hwDetail');
var btn = app.createButton('Submit Homework');
//Create handler which will execute 'Submit Homework(e)' on clicking the button
var handler = app.createServerClickHandler('Submit Homework');
handler.addCallbackElement(panel);
//Add this handler to the button
btn.addClickHandler(handler);
//Add all the elemnts to the panel
panel.add(startDateLabel)
.add(startDate)
.add(endDateLabel)
.add(endDate)
.add(hwTitleLabel)
.add(hwTitle)
.add(hwDetailLabel)
.add(hwDetails)
.add(btn);
//Add this panel to the application
app.add(panel);
//return the application
return app;
}
function createEvents(e){
//Get the active application
var app = UiApp.getActiveApplication();
try{
//get the entries;
var startDate = e.parameter.startDate;
var endDate = e.parameter.endDate;
var hwTitle = e.parameter.hwTitle;
var hwDetails = e.parameter.hwDetails;
//Get the calendar
var cal = CalendarApp.getCalendarsByName('Paul Lim')[0];//Change the calendar name
var startDate = startDate;
var endDate = endDate;
//Create the events
cal.createEvent(hwTitle, startDate, endDate,{description:hwDetail});
//Log the entries in a spreadsheet
var ss = SpreadsheetApp.openById('1PTSsvjsvb-UVuJ_z9WoLGVZ01YigjLQ5nCi7ujU4Gek');//Change the spreadhseet key to yours
var sheet = ss.getSheets()[0];
sheet.getRange(sheet.getLastRow()+1, 1, 1, 5).setValues([[new Date(), endDate, hwTitle, hwDetails]]);
//Show the confirmation message
app.add(app.createLabel('Homework created successfully'));
//make the form panel invisible
app.getElementById('panel').setVisible(false);
return app;
}
//If an error occurs, show it on the panel
catch(e){
app.add(app.createLabel('Error occurred: '+e));
return app;
}
}
Use createServerHandler
instead... to avoid this kind of problems I'd suggest you use the autocomplete feature in the script editor: if you type "create" and hit control-space you'll see all the available methods, including the deprecated ones being stroked through.
There is also another issue in your code: you forgot to set names to your date Widgets, they won't return any value in the server handler function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.