I've got a spreadsheet with a button that links to a function in my Google Apps Script, openInputDialog
. My desired outcome is that pushing the button opens an HTML UI where a user can input text to five fields, and the text is taken from that input and appended to a new row at the bottom of the spreadsheet. I'm experiencing an issue where when clicking the submit
button nothing happens; the dialog does not close, and more importantly, there is not a new row appended with the values that are input in it.
The code is as follows:
addItem.gs:
function openInputDialog() {
var html = HtmlService.createHtmlOutputFromFile('Index')
return HtmlService.createHtmlOutputFromFile('Index')
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getUi()
.showModalDialog(html, 'Add Item');
}
function itemAdd() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
sheet.appendRow([" ", 'category', 'item', 'manupub', 'details', 'quantity']);
}
Index.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<br>
<form>
Category:<br>
<input type="text" name="category">
<br>
Item:<br>
<input type="text" name="item">
<br>
Manufacturer or Publisher:<br>
<input type="text" name="manupub">
<br>
Details:<br>
<input type="text" name="details">
<br>
Quantity:<br>
<input type="text" name="quantity">
<br><br>
<input type="submit" value="Add Item">
</form>
<script>
google.script.run.addItem();
</script>
</html>
I'm pretty sure that the answer to my issue lies with some simple problem or misuse of some part of this script, but my programming knowledge is currently not good enough to properly understand the Google Apps Script documentation that I've been reading.