我目前正在使用Google脚本创建请假申请表。用户提交表单后,它将向主管发送电子邮件。主管可以批准或拒绝,并可以从电子邮件本身中说明拒绝的原因。但是用户既收到请求待处理电子邮件,又收到需要信息电子邮件。
function sendEmail(e) {
var Email = e.values[1];
var Name = e.values [2];
var LeadEmail = e.values [3]
var StartDate = e.values[4];
var EndDate = e.values[5];
var Reason = e.values[6];
var url ='https://script.google.com/macros/s/AKfycbwtoHhUZPX2bEbbdiEjak4WwUZYBj5ulrSbUJlDzemgcqTMIG0/exec';
var resubmitFormUrl='https://docs.google.com/forms/d/e/1FAIpQLSdNAeCsbTfntizgpMeOdbJdiWKRQKngo0hWsFaUmECFVMt94w/viewform?usp=sf_link'
var approve = url + '?approval=approve'+'&reply='+Email;
var reject = url + '?approval=reject'+'&reply='+Email;
var moreinfo = url + '?approval=moreinfo'+'&reply='+Email;
var html ="<body>"+
"<h2>Please review</h2><br />"+
"Email id : " + Email + "<br/>"+
"Name : " + Name + "<br/>"+
"Lead Email ID: " + LeadEmail + "<br/>"+
"StartDate : " + StartDate + "<br/>"+
"EndDate : " + EndDate + "<br/>"+
"Reason : " + Reason + "<br/>"+
"<a href ="+ approve +"> Approve</a><br />"+
"<a href ="+reject+">Reject</a> <br />"+
"<a href ="+moreinfo+">MoreInfo</a> <br />"+
``` "</body>";
MailApp.sendEmail(LeadEmail, "Approval Request", "what no html?", {htmlBody: html});
var htmll ="<body>"+
"<h3>You have submitted these details</h3>"+
"Email id : " + Email + "<br/>"+
"Name : " + Name + "<br/>"+
"Lead Email ID: " + LeadEmail + "<br/>"+
"StartDate : " + StartDate + "<br/>"+
"EndDate : " + EndDate + "<br/>"+
"Reason : " + Reason + "<br/>"+
``` "<h3>You'll be notified soon about the approval ```decision</h3>"+
"<body/>";
MailApp.sendEmail(Email,"Approval Request","What no html?",{htmlBody:htmll});
var html2 ="<body>"+
`` "<h3>You have submitted the below details,but Approver require more information</h3>"+
"Email id : " + Email + "<br/>"+
"Name : " + Name + "<br/>"+
"Lead Email ID: " + LeadEmail + "<br/>"+
"StartDate : " + StartDate + "<br/>"+
"EndDate : " + EndDate + "<br/>"+
"Reason : " + Reason + "<br/>"+
"<h3>click the link </h3><a href = "+resubmitFormUrl+">Re-Submit </a> <h3>form for Approval</h3> "+
"<h3>You'll be notified soon about the approval decision</h3>"+
"<body/>";
````MailApp.sendEmail(Email,"Approval Request","What no html?",{htmlBody:html2});
}
function doGet(e)
{
var answer = (e.parameter.approval==="approve") ? 'is Approved': (e.parameter.approval==="reject") ? 'Not approved' : 'Requires More Information' ;
var msg = "Your leave is: " + answer ;
if(e.parameter.approval != "moreinfo")
MailApp.sendEmail(e.parameter.reply,"Approval Request",msg);
}
预期:用户提交了请求表格
如果我犯了一个错误,我深表歉意,我仍然是一个初学者。因此,请您帮助我。
答案 0 :(得分:0)
也许像这样更改doGet
可能会有所帮助? (我无法确定是否进行测试):
function doGet(e) {
var answer = '';
// Checks for each value ('approve', 'reject', or 'moreinfo') separately
// Now, 'moreinfo' is not assumed by default (might matter)
if (e.parameter.approval === "approve") { answer = 'is Approved'; }
else if (e.parameter.approval === "reject") { answer = 'Not approved'; }
else if (e.parameter.approval === "moreinfo") { answer = 'Requires More Information'; }
// In case e.parameter.approval somehow matches none of the above
else { answer = "Undetermined yet -- please contact us"; }
var msg = "Your leave is: " + answer;
// Uses strict equality (might matter)
if (e.parameter.approval !== "moreinfo"){
// Includes curly braces around statement (probably unnecessary)
MailApp.sendEmail(e.parameter.reply, "Approval Request", msg);
}
}