J How to send an email in google sheets if multiple conditions exist



  • Missing } in compound statement. (line 27, file "Code")

    I get this error when running the following:
    function conditionalMail(){
    var sheet = SpreadsheetApp.getActiveSheet();
    var maxBookings = sheet.getRange("A2").getValue();
    var roomNum = sheet.getRange("A1").getValue();
    var range = sheet.getRange("A5:B6");
    var bookingData = range.getValues();
    for (i in bookingData) {
    var row = bookingData[i]
    var bookingsCount = row[0];
    var timing = row[1];
    if (bookingsCount > maxBookings) {
    MailApp.sendEmail("[email protected]","Overbooked rooms","The " + timing + " meeting in " + roomNum + " is overbooked");
    function conditionalMail(){
    var sheet = SpreadsheetApp.getActiveSheet();
    var maxBookings = sheet.getRange("C2").getValue();
    var roomNum = sheet.getRange("C1").getValue();
    var range = sheet.getRange("C5:D6");
    var bookingData = range.getValues();
    for (i in bookingData) {
    var row = bookingData[i]
    var bookingsCount = row[0];
    var timing = row[1];
    if (bookingsCount > maxBookings) {
    MailApp.sendEmail("[email protected]","Overbooked rooms","The " + timing + " meeting in " + roomNum + " is overbooked");
    }
    }
    }


  • administrators

    @jrenforth I don't know if you posted the wrong code above or the code itself is like that! There are 2 functions named conditionalMail() and the first function is not closed either. Please check your code again. There are too many errors.


Log in to reply
 

Looks like your connection to Codingislove Forum was lost, please wait while we try to reconnect.