javascripthtmlemailgoogle-apps-scripthtml.textboxfor

Is there a way to get text field input values from a html email


I am currently creating a leave application form using google script. After the user submits the form, it sends an email to a supervisor. The supervisor is able to approve or reject and able to state reason of rejection from the email itself. I got the workflow all done and working, now i am just stuck at retrieving a value from a text field input in the email and set the retrieved value in a spreadsheet. Any suggestions or other workarounds?

I've tried document.getElementId() but document is not defined here so... I am not too sure if the code should be in the doGet function however i dont think its likely.

function sendingEmail(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Logger.log(sheet.getRange(25, 14).getValue());
var employeeName = e.values[1];
var email = e.values[2];
var email2 = e.values[3];
var supervisor = e.values[4];
var employeeNo = e.values[5];
var typeofLeave = e.values[6];
var leaveShift = e.values[8];
var otherReason = e.values[7];
var reason = e.values[9];
var dateFrom = e.values[10];
var dateTo = e.values[11];
var row = e.range.getRow();
var supervisoremail = sheet.getRange(row, 14);
var status = sheet.getRange(row, 13);
var rejectReason = sheet.getRange(row, 15);

var url = 'https://script.google.com/macros/s/******exec?';

var approve = url +'approval=true'+'&reply='+ email +'&reply2='+ email2 +'&row=' + row; 
var reject = url +'approval=false'+'&reply='+ email +'&reply2='+ email2 +'&row=' + row;

var html = "<body>"+
              "<h2>Please review the leave application</h2><br />"+
                "Employee Name :"+ employeeName + "<br />"+
                "Employee Email :" + email + "<br />"+
                "Employee Email opt :" + email2 + "<br />"+
                "Supervisor Name :" + supervisor + "<br />"+
                "Employee No :" + employeeNo + "<br />"+
                "Type of Leave :" + typeofLeave + "<br />"+
                "Leave Shift :" + leaveShift + "<br />"+
                "Other Reason for Leave :" + otherReason + "<br />"+
                "Reason :" + reason + "<br />"+
                "From :" + dateFrom + "<br />"+
                "To :" + dateTo + "<br />"+
                  "<a href="+approve +">Approve</a><br />"+
                    "<a href="+ reject +">Reject</a><br />"+
                    <p> //TEXT FIELD INPUT HERE
        <input type="text" value="" name="Email" placeholder="Reject  Reason" id="rejectreason"/> 
    </p>
         "</body>";
if (supervisor == 'Geralt'){
status.setValue('PENDING');
supervisoremail.setValue('GeraltofRivia@gmail.com.my'); //set supervisor emails  into spreadsheet
MailApp.sendEmail("GeraltofRivia@gmail.com.my", "Approval Request", "What no HTML?", {htmlBody: html}) 
var y = p.getElementById('rejectreason').value; //CODE ENTERS HERE?
rejectReason = setValue(y); //SETVALUE THE STRING INTO SPREADSHEET
}
else if (supervisor == 'Ciri'){
status.setValue('PENDING');
supervisoremail.setValue('Ciri@gmail.com'); //set supervisor emails into spreadsheet
MailApp.sendEmail("Ciri@gmail.com", "Approval Request", "What no HTML?",  {htmlBody: html}); /* ciri email here*/
}

email output:
Please review the leave application

Employee Name :Yennefer
Employee Email :
Employee Email opt :yenofvengerberg@gmail.com
Supervisor Name :
Employee No :yen T138
Type of Leave :Annual Leave
Leave Shift :Full day
Other Reason for Leave :
Reason :holiday
From :12/2/2018
To :12/3/2018
Approve
Reject
Reject reason (text field)

This is what the email html looks like. i wanted the string or the value from the text field to be updated in the spreadsheet once the reject/approve link is clicked.


Solution

  • The short answer is no. E-mails can just show information not recieve them. The best option would be you put a link inside the email`s body and when the user clicks on it, its redirect the user to a page, where he can fill the fields that you're asking