我正在尝试创建一个网络表单应用程序,该应用程序允许某人填写表单并在需要时上传文件。我目前遇到的问题是,如果用户没有提交文件,它将提示“意外错误”提示。但是,该表单确实将数据提交到电子表格中而没有错误。
我需要的是,如果用户没有上传表单,应用程序不会提示错误。
// Script-as-app template.
var submissionSSKey = '0Aud1xlxCWoZydGllMDNwTEVhS3RqSlUyZXBwQVZTcXc';
function doGet(e) {
var app = UiApp.createApplication().setTitle('Loan Registration Processing');
var panel = app.createFormPanel();
var grid = app.createGrid(5,2).setId('loanGrid');
var nameLabel = app.createLabel('Name:');
var nameTextBox = app.createTextBox().setName('name').setWidth('150px').setName('name').setId('name');
var depLabel = app.createLabel("Department:");
var depSelec = app.createListBox().setWidth('130px').setName('department').setId('department');
depSelec.addItem('Select Option');
depSelec.addItem('Cashier');
depSelec.addItem('Text Books');
depSelec.addItem('Greeter');
depSelec.addItem('Runner');
depSelec.addItem('Line Control');
depSelec.addItem('IDB');
var messageLabel = app.createLabel('Message:');
var messageTextBox = app.createTextArea().setWidth('300px').setHeight('150px').setName('message').setId('message');
var submitButton = app.createSubmitButton('<B>Submit</B>');
//var warning = app.createHTML('<B>PLEASE WAIT WHILE DATA IS UPLOADING<B>').setStyleAttribute('background','yellow').setVisible(false)
//file upload
var upLoadTypeLabel = app.createLabel('Upload Schedule:');
var upLoad = (app.createFileUpload().setName('thefile'));
//Grid layout of items on form
grid.setWidget(0, 0, nameLabel)
.setWidget(0, 1, nameTextBox)
.setWidget(1, 0, depLabel)
.setWidget(1, 1, depSelec)
.setWidget(2, 0, messageLabel)
.setWidget(2, 1, messageTextBox)
.setWidget(3, 0, upLoadTypeLabel)
.setWidget(3, 1, upLoad)
.setWidget(4, 0, submitButton)
//.setWidget(4, 1, warning)
var cliHandler = app.createClientHandler();
submitButton.addClickHandler(cliHandler);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var comp = 'N/A'
var LoanType = e.parameter.name;
var borrower = e.parameter.department;
var amount = e.parameter.message;
//app.getElementById('info').setVisible(true).setStyleAttribute('color','red');
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheets()[0];
var lastRow = sheet.getLastRow();
var targetRange = sheet.getRange(lastRow+1, 1, 1, 4).setValues([[comp,LoanType,borrower,amount,]]);
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.thefile;
var doc = DocsList.getFolderById('0B-d1xlxCWoZybk1oUXhLZV91SDQ').createFile(fileBlob)
.rename(borrower+' - '+LoanType);
return app;
}