I am coding a tool for myself and my classmates that will create a google doc and email it to the selected teacher, using all fields that are filled in and filling all those that are not with the defaults for the selected subject, say language arts, but the function that takes the selected information and uses it to send the email is not executing. I've checked the executions for the project, and the function, customDoc()
, has not once been executed. I suspect it's a problem with my HTML, as I have not seen any error messages when I tested the function in the editor to see if there were any syntax errors, but it was spot clean, just never executed. Here's my code, and while the error is likely in the HTMl I will provide my JS too.
function doGet() {
return HtmlService.createHtmlOutputFromFile('Index.html');
}
function showDialoge() {
SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('Index.html'), 'Test');
}
function customDoc(clicked_id) {
var d = new Date();
var s = (d.getDate()) + '/' + (d.getMonth() + 1) + '/' + d.getFullYear();
console.log(s);
var cycler = clicked_id
var math = ['esmith3@op97.org', 'math for ']
var LA = ['cborah@op97.org', 'la for ']
var science = ['lgrimaldi@op97.org', 'science for ']
var is = ['charrington@op97.org', 'I&S for ']
var span = ['vlagioia@op97.org', 'Espanol para ']
var presets = [math, LA, science, is, span]
var email1 = document.getElementById('Email')
var subject1 = document.getElementById('Sub')
var docName1 = document.getElementById('docName')
var message1 = document.getElementById('message')
var email = null
if (email1 != ' ') {
email = email1
} else {
email = presets[cycler];
[1];
}
var subject = null
if (subject1 != ' ') {
subject = subject1
} else {
subject = presets[cycler];
[2]; + s
}
var doc = null
if (docName1 != ' ') {
doc = docName1
} else {
doc = presets[cycler];
[2]; + s
}
var document = documentApp.create(doc)
var url = document.getUrl();
var message = null
if (message1 != ' ') {
message = message1 + '' + url
} else {
message = url
}
GmailApp.sendEmail(email, subject, message);
}
<!DOCTYPE html>
<script src="Code.gs"></script>
<html>
<h1>CREATE DOC</h1>
<body>
</body>
<p>Email</p>
<input type='text' id='Email' value=' ' style="border-radius: 20px; border-color: crimson; border-width:20px; ">
<p style=" font-family: Times New Roman, Times, serif;">Doc name</p>
<input type='text' id='docName' value=' ' style="border-radius: 20px; border-color: crimson; border-width:20px; ">
<p>Subject</p>
<input type='text' id='Sub' value=' ' style="border-radius: 20px; border-color: crimson; border-width:20px; ">
<p>message</p>
<input type='text' id='message' value=' ' style="border-radius: 20px; border-color: crimson; border-width:20px; ">
<h2>Fill blanks for subject: </h2>
<button id='2' onclick=c ustomDoc(this.id)> LA </button>
<button id='3' onclick=c ustomDoc(this.id)> Science </button>
<button id='4' onclick=c ustomDoc(this.id)> Individuals and societies </button>
<button id='5' onclick=c ustomDoc(this.id)> Spanish </button>
<button id='1' onclick=c ustomDoc(this.id)> math </button>
</html>
See Question&Answers more detail:os