I have a spreadsheet containing all of the annual leave balances for each staff member. I have a form that the staff will fill out, and I would like it to pull the their data from the spreadsheet and send them an email with the result.
I am having trouble with the matching of form data to the spreadsheet data, and extracting the related cells. Here is the code:
function SendGoogleForm(e) {
try {
var subject = "Leave Balance Request";
var s = SpreadsheetApp.openByUrl("url").getSheetByName("Check Leave");
var email = e.namedValues["BCA National email address"];
var sheet = SpreadsheetApp.openByUrl("url").getSheetByName("Leave Summary");
var cell = sheet.getRange("F3:F3");
var getcell = cell.getCell(1,1);
var pdate = getcell.setValue(e.namedValues['END date of leave requested']);
var annualvalue = sheet.getRange("H6:H").getValues();
var emaildata = sheet.getRange("A6:A").getValues();
var username = e.namedValues["Username"];
var message = "Your" + " " + e.namedValues["Type of leave requested"] + " " + "balance is below" + "\n\n";
if (username == emaildata) { message += "Annual Leave" + " : " + annualvalue + "\n\n"; }
MailApp.sendEmail(email, subject, message);
}
catch (e) {
Logger.log(e.toString());
}
}
I tried this: How do I search for and find the coordinates of a row in Google Spreadsheets
But couldn't get it to work...
Any suggestions would be greatly appreciated!