Below is a code that sends emails with alerts created from data in a spreadsheet.
The line if(ce2 != 'no value'){ Has a Syntax error as do the following two if statements: if(al2 != 'no value'){ and if(cc2 != 'no value'){; however, the first if statement, if(ce2 != 'no value' || al2 != 'no value' || cc2 != 'no value'){, does not. I cannot find the error. I'm sure it's something stupid I haven't clicked onto, though.
I have tried using the correct if statement in place of the ones with the error, but it still has the error. I have played with the positioning of the +'s to see if that has any effect. The function works if the if lines and their corresponding }'s are commented out. I also changed 'empty' to 'no value' in case that was a 'reserved' word or some such.
function emailAlerts() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('EmailAlerts');
var sub = s.getRange('F5').getValue();
var nm2 = s.getRange('C11').getValue();
var em2 = s.getRange('D11').getValue();
var ce2 = s.getRange('E11').getValue();
var al2 = s.getRange('F11').getValue();
var cc2 = s.getRange('G11').getValue();
if(ce2 != 'no value' || al2 != 'no value' || cc2 != 'no value'){
MailApp.sendEmail(em2, sub, '',{
htmlBody: 'Good morning '+nm2+
',<br><br><b>Your alerts:</b><br><br>'+
if(ce2 != 'no value'){
'<b>CONTRACTS EXPIRING</b><br>'+
ce2+'<br><br>'+
}
if(al2 != 'no value'){
'<b>AUDIO LINES EXPIRING</b><br>'+
al2+'<br><br>'+
}
if(cc2 != 'no value'){
'<b>COLD CALLS TO FOLLOW UP</b><br>'+
cc2+'<br><br>'+
}
'Kind regards,<br>XXX'
});
}
}