我有以下java,当用户提交新目标时,将一些带有一些数据的简单表单提交到Google表格中,我希望他收到两个确认,一封作为发送给他的电子邮件,另一封作为窗口确认接收新数据。
然而,虽然我多次尝试过,但两个函数sendemail和openDialogSuccess都没有响应。
function doGet() {
return HtmlService.createHtmlOutputFromFile('set_or_targets')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
function close() {
google.script.host.close()
}
function openDialog() {
var html = HtmlService.createHtmlOutputFromFile('set_or_targets')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setHeight(650);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(html,' ');
}
function sendemail(e) {
var userEmail = Session.getActiveUser().getEmail(); //email of the user
var subject = "Form submitted"; //the email subject
var d = new Date(); // the data of the update
if (d.getHours() >= 17) {
var ontime = "Because you updated the target after 17:00 your target will be updated in two days";
} else {
var ontime = 'Your update was recorded and will take into consideration starting tomorrow';
} // this check if the update happened before or after 17:00
var message = "Thank you, " + userEmail + " For submitting a new Target on " + d + " " + ontime;
MailApp.sendEmail(userEmail, subject, message);
}
function openDialogSuccess(e){
var html = HtmlService.createHtmlOutputFromFile('Thank_You')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(html,' ');
}
function SetTarget(formObject){
var AT = formObject.AT;
var BE = formObject.BE;
var CH = formObject.CH;
var DE = formObject.DE;
var DK = formObject.DK;
var ES = formObject.ES;
var FI = formObject.FI;
var FR = formObject.FR;
var IT = formObject.IT;
var NL = formObject.NL;
var NO = formObject.NO;
var PL = formObject.PL;
var SE = formObject.SE;
var UK = formObject.UK;
var ios = formObject.ios;
var android = formObject.android;
var windows = formObject.windows;
var Target=formObject.TargetOR;
var user=Session.getActiveUser().getEmail();
var d = new Date();
var ss = SpreadsheetApp.openById('aa');
var outputSheet = ss.getSheetByName('Responses');
var r = outputSheet.getLastRow()+1;
if(ios=='on'){CheckCountries('IOS')};
if(android=='on'){CheckCountries('Android')};
if(windows=='on'){CheckCountries('Windows')};
function CheckCountries(objective){
if(AT== 'on') {AddData('AT',objective)};
if(BE== 'on') {AddData('BE',objective)};
if(CH== 'on') {AddData('CH',objective)};
if(DE== 'on') {AddData('DE',objective)};
if(DK== 'on') {AddData('DK',objective)};
if(ES== 'on') {AddData('ES',objective)};
if(FI== 'on') {AddData('FI',objective)};
if(FR== 'on') {AddData('FR',objective)};
if(IT== 'on') {AddData('IT',objective)};
if(NL== 'on') {AddData('NL',objective)};
if(NO== 'on') {AddData('NO',objective)};
if(PL== 'on') {AddData('PL',objective)};
if(SE== 'on') {AddData('SE',objective)};
if(UK== 'on') {AddData('UK',objective)};
};
function AddData(country, objective){
outputSheet.getRange(r, 1).setValue(d)
outputSheet.getRange(r, 2).setValue(Session.getActiveUser().getEmail());
outputSheet.getRange(r, 3).setValue(country);
outputSheet.getRange(r, 4).setValue(objective);
outputSheet.getRange(r, 5).setValue(Target);
r=r+1
};
doGet();
}
感谢您的帮助
答案 0 :(得分:-1)
需要在SetTarget函数的末尾调用该函数