I'm trying to capture a date range that will be used inside a Document container-based GAS. I've been successful displaying a dialog box that shows two jquery datepicker objects using Serge's great example in this post: Date picker in HTMLService / Google Apps Script . . ...but, how can I return the two date values back to my GAS code from the html logic?
Thanks in advance!
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('Create Calendar')
.addItem('Provide Date Range', 'showDialog')
.addToUi();
}
function showDialog() {
var html = HtmlService.createHtmlOutputFromFile('dateDialog')
.setWidth(500)
.setHeight(400);
DocumentApp.getUi()
.showModalDialog(html, 'Please provide a Date Range');
Logger.log("HTML return = %s", html.getContent()); // What does html contain?
}
==================== dateDialog.html ======================
<div class="demo" >
<style type="text/css"> .demo { margin: 30px ; color : #AAA ; font-family : arial sans-serif ;font-size : 10pt }
p { color : red ; font-size : 11pt }
</style>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/cupertino/jquery-ui.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<p>Please select a date below :</p>
<p> Start Date : <input type="text" name="StartDate" id="startdatepicker" /> </p>
<p> End Date : <input type="text" name="EndDate" id="enddatepicker" /> </p>
<script>
$( "#startdatepicker" ).datepicker({
showWeek: true,
firstDay: 0,
});
</script>
<script>
$( "#enddatepicker" ).datepicker({
showWeek: true,
firstDay: 0,
});
</script>
<input type="button" value="Close" onclick="google.script.host.close()" />
</div>
Prepare a server-side function to receive your input. This one only logs it:
Change the button handler in your html. Instead of closing the dialog, collect the input data and pass it to the server function using
google.script.run
. Attach handler to the runner; a success handler will close the window, for example. A failure handler will display server-side errors.Add this script to the bottom of your html: