我目前正在使用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);
}
预期:用户提交请求表格后
应发送给用户的确认电子邮件以及给主管的批准电子邮件
单击“批准”链接后,应发送给用户的电子邮件说明已批准请假。
在单击“拒绝”链接后,应该发送给用户的电子邮件指出请假已被拒绝。
单击“需要信息”链接后,应向用户发送一封电子邮件,要求他提交有关他为什么要请假的更多信息。
如果我犯了一个错误,我深表歉意,我仍然是一个初学者。因此,请您帮助我。
最佳答案
也许像这样更改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);
}
}
关于javascript - 功能doGet在“请假批准”脚本中不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57773522/