I'm trying to create a simple workflow using Google Forms which sends an automated e-mail for approval.
function sendEmail(e){
var requestorEmail = e.values[1];
Logger.log('replyEmail: ' + requestorEmail);
var SupervisorsEmail = e.values[2]; //manager e-mail
var ApplicationID = e.values[3];
var ApplicationDate = e.values[4]; //dateconfirmationSent
var ApplicantName = e.values[5]; //interpreter name
var MBO = e.values[6];
var Processor = e.values[7];
var ShortReason = e.values[8];
var ReasonCode = e.values[9];
var approval = e.values[10]; //the one we need to modify
var url ='https://script.google.com/a/macros/bbva.com/s/AKfycbz5GL9xxSmRcDjUFRJdn4qw7TrfaWNUFD8XwHNlqsCxNPRpOd49/exec';
/**might be that the & needs to be a ?*/
var approve = url + '?approval=true'+'?reply='+requestorEmail;
var reject = url + '?approval=false'+'?reply='+requestorEmail;
var html = "<HTML><body>"+
"<h2>Pend Request</h2><br />"
+"<P>" + ApplicationID +" " + ApplicationDate
+"<p>" + "MBO: "+ MBO
+"<p>" + "Processor: " + Processor
+"<p>" + "Short Reason: "+ ShortReason
+"<p>" + "requester: "+ requestorEmail
+"<p>" + "Reason Code: "+ ReasonCode+ " "+
"<p>"+
"<a href="+ approve +">Approve</a><br />"+
"<p>"+
"<a href=" +reject+">Reject</a><br />"+
"</HTML></body>";
MailApp.sendEmail(SupervisorsEmail, "Approval Request", "what no html?", {htmlBody: html});
}
function doGet(e) {
var app = UiApp.createApplication();
var requestorEmail = e.values[1];
Logger.log('replyEmail: ' + requestorEmail);
var aprovalResponce = (e.parameter.approval == 'true') ? 'Approved.' : 'Sorry, your request has been denied.';
var msg = "Your manager said :" + aprovalResponce;
//var replyEmail = e.values[1];
//Logger.log(replyEmail);
MailApp.sendEmail(requestorEmail, "Approval Request", msg);
var helloWorldLabel = app.createLabel(msg);
app.add(helloWorldLabel);
return app;
}
When i run the actual program, everything works fine. But when i receive the e-mail, whether I click approve or reject, I receive an "Invalid email:undefined" error. I'm new to GAS and have researched a lot of tutorials, examples, etc. But it's few that are helpful since the big changes that were recently made.
Try changing the second question mark in the URL to an ampersand. What you have now:
var approve = url + '?approval=true'+'?reply='+requestorEmail;
var reject = url + '?approval=false'+'?reply='+requestorEmail;
Change:
+'?reply='
To:
+'&reply='