I have implemented the Google Apps Script code to show confirmation message, I am successful in showing the message using the Label but I am trying to display confirmation message in a box instead of the label so that it would be clear to user that they submitted the files successfully and can hit the OK button in that box. I tried achieving this goal using this code below but it shows following error message:
"Error encountered: SpreadsheetApp.getUi() can only be called from a script bound to the new version of Google Sheets."
This is the new Google Spreadsheet I have created to code Google Apps Script, but I copied and pasted the existing code.
This is the code I tried to use to show confirmation message box (which is showing error message as listed above):
var ui = SpreadsheetApp.getUi();
var userChoice = ui.alert(
'Thank You for uploading files',
ui.ButtonSet.OK);
if (userChoice == ui.Button.OK) {
ui.alert('Operation Confirmed.');
} else {
ui.alert('Operation Halted.');
}
Below is the code that I am successful showing the confirmation message in label:
// Create form to hold the file upload buttons for choosing a file and uploading
var form = app.createFormPanel().setId('frm').setEncoding('multipart/form-data');
var formContent = app.createVerticalPanel();
form.add(formContent);
formContent.add(app.createLabel('All of the following files must be submitted prior to completing the form').setHeight('25px').setStyleAttributes(_lbl).setStyleAttribute('font-size','20px'));
formContent.add(app.createLabel('Reference Letter').setHeight('20px').setStyleAttributes(_lbl));
formContent.add(app.createFileUpload().setName('Reference'));
formContent.add(app.createLabel('Reference Letter 2').setHeight('20px').setStyleAttributes(_lbl));
formContent.add(app.createFileUpload().setName('Reference2'));
formContent.add(app.createLabel('Reference Letter 3').setHeight('20px').setStyleAttributes(_lbl));
formContent.add(app.createFileUpload().setName('Reference3'));
formContent.add(app.createSubmitButton('Submit File Uploads'));
function doPost(e) {
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.Reference;
var doc = DocsList.createFile(fileBlob);
var app = UiApp.getActiveApplication();
var fileBlob2 = e.parameter.Reference2;
var doc = DocsList.createFile(fileBlob2);
var app = UiApp.getActiveApplication();
var fileBlob3 = e.parameter.Reference3;
var doc = DocsList.createFile(fileBlob3);
var app = UiApp.getActiveApplication();
//Display a confirmation message
var label = app.createLabel('Thank You for uploading files').setStyleAttribute('font-weight','bold').setStyleAttribute('font-size','1.1em');
app.add(label);
return app;
}
Is there any way to show confirmation message in box instead of in label? I have to show confirmation message for other part of the program also.
Thanks
You could use DialogBox or PopupPanel instead of label. Check linked documentation for details.
On a side note, your doPost() function code sets var app
three times, which is unnecessary. You might also want to edit your code to account for not all 3 files being selected and uploaded.
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.