I want to write a program for a friend, who is working in a Human Resources department, that automatically sends letters of refusals to rejected applicants.
To have an overview of the application, he uses a spreadsheet where names, position, interviews, etc. are recorded. Every applicant has one row in the document.
If he rejects a candidate, he puts an "A" in a specific column. I want the program to recognize those "A"s, write an email to the applicant and then put the word "done" in the cell next to the "A".
The code is the following:
function Absagen() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange(1, 5);
var endRow = range.getValue();
var startRow = 1;
var numRows = endRow;
var dataRange = sheet.getRange(startRow, 1, numRows, 10)
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0];
var absage = row[8];
var absageSent = row[9];
var mailLanguage = row[3];
var gender = row[7];
var firstName = row[5];
var lastName = row[6];
Logger.log("absage = "+ absage +" ?");
if (absage == "A" && absageSent != "DONE" && mailLanguage == "2" && gender == "1"){
var message = "<HTML><BODY>"
+"blablabla";
var subject = "Ihre Bewerbung";
MailApp.sendEmail(emailAddress, subject, "", {htmlBody: message});
var destRow = Number(startRow); ++ destRow;
sheet.getRange((destRow+i), 10).setValue("DONE");
SpreadsheetApp.flush();
}
}
}