我有一个Google表单,该表单基于onFormSubmit()函数通过Google Apps脚本发送自动电子邮件触发器。在此电子邮件中,有一个链接触发打开index.html页面。在index.html页面中,有2个批准链接(批准/拒绝),并且在单击任何一个批准链接时,都会向申请人发送通知电子邮件。
示例代码如下:
code.gs
function onFormSubmit(e) {
// Capture Data
var values = e.namedValues;
var name = values['Name'];
var email = values['Email'];
var url = 'my-web-app-url';
var htmlBody = var htmlBody = '<ul>';
htmlBody += '<li>' + 'Name: ' + name + '</li>';
htmlBody += '<li>' + 'Email: ' + period + '</li>';
htmlBody += '</ul>';
// Link to open HTML page
var open = url + '?approval=open' + '&reply=' + email + '&name=' + name;
var messageBody = 'Hi ' + ', <br><br>' +
'You have received a new form submission that requires your approval.<br><br>' + '<a href='+ open + '>Open Link</a>';
// Sends email to Reporting Officer
MailApp.sendEmail({
to: 'test@example.com',
subject: 'Approval Required',
htmlBody: messageBody
});
}
function doGet(e) {
// Capture Applicant's Data
var name = e.parameter.name;
var email = e.parameter.reply;
var approval = e.parameter.approval;
if (approval == 'open') {
// Renders HTML
return HtmlService.createHtmlOutputFromFile('index');
} else {
// If approval is 'true' or 'false', notify applicant
var emailBody = 'Dear ' + name + ', <br><br>' +
'Your application has been approved.';
MailApp.sendEmail({
to: email,
subject: 'Application Approved',
htmlBody: emailBody
});
}
}
function generateMessage() {
var name = e.parameter.name
var approval = e.parameter.approval
if (approval = 'true') {
var msg = "You have approved " + name + "'s application. An email has been sent to him/her.";
} else {
var msg = "You have rejected " + name + "'s application. An email has been sent to him/her."
}
return msg;
}
function generateApprovalLinks() {
if (approval == 'open') {
// Links to Approve / Reject
var approve = url + '?approval=true' + '&reply=' + email + '&name=' + name;
var reject = url + '?approval=false' + '&reply=' + email + '&name=' + name;
return approve;
return reject;
}
}
index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
google.script.run.generateMessage();
google.script.run.generateApprovalLinks();
document.getElementById("msg").innerHTML = msg;
</script>
</head>
<body>
<section class="hero">
<div class="hero-body">
<div class="container">
<h1 class="title">Success</h1>
<p id="msg"></p>
<!-- Add an input field to capture remarks -->
<label name="remarks">Remarks: </label>
<input type="text" name="remarks">
<!-- Output approval links -->
<script type="text/javascript">
document.write(approve);
document.write(reject);
</script>
<!-- But how do I send this data back as parameter in my url? -->
</div>
</div>
</section>
</body>
</html>
但是,我不想直接从触发电子邮件中单击批准/拒绝链接,而是希望允许“批准人”通过在HTML输出中添加文本输入字段来添加一些文本注释。 / strong>。另外,我想将此批准链接移到同一HTML输出页面,然后用户可以将其备注作为url参数发送回Apps脚本中的doGet()函数在发送给用户的电子邮件中添加备注。
这有可能吗?有人对我应该怎么做有任何建议吗?