vendredi 22 avril 2016

If/Else Statement not working to send different emails

I am trying to write a script in google sheets that will send one of two different emails based on the response to a multiple choice question. I can get my if/else statement to send either one or the other of the emails but it will not recognize the text of the multiple choice answer and send the correct email.

Here is the full script:

function sendEmails() {
 var sheet = SpreadsheetApp.getActiveSheet();
 var startRow = 2;  // First row of data to process
 var numRows = 1;
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 8)
// Fetch values for each row in the Range.
 var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var title = row[1];  // First column
var startDate = row[3];       // Second column
var endDate = row[4];
var description = row[2];
var location = row[6];
var eventImport = row[5];
var emailAddress = row[7];    
var multchoice = row[8];

if (multchoice == "Part Time") {
var subject = "New Hire Part Time Email - " + startDate;
var emailBody = "Congradulations"
var htmlBody = "Congradulations! Part time person"
MailApp.sendEmail (emailAddress, subject, emailBody);}

else {   
var subject = "New Hire Appointment - " + startDate;
var emailBody = "Congratulations! We are excited"
var htmlBody = "Congratulation! </i><br/>&nbsp;<br/> We are excited"
MailApp.sendEmail(emailAddress, subject, emailBody);}

} }

I believe the problem is here:

 if (multchoice == "Part Time")

Any help is greatly appreciated! I am a novice

Aucun commentaire:

Enregistrer un commentaire