javascript - Are if and else if statements bugged in Google Apps Script? -
i'm new gas , javascript in general , have searched far , wide find answer why isn't working, haven't found solution. wondering if 1 of guys find problem. here's code:
function maintenancerequest() { var findfirstrequest = gmailapp.search("to:censored label:ems-request , is:unread", 0, 1)[0]; var firstrequest = findfirstrequest.getmessages()[0]; var parserequest = firstrequest.getplainbody(); var requeststring = string(parserequest); if ("mark archived mail read" == requeststring) { markarchivedasread(); findfirstrequest.movetoarchive(); } else if ("cleanup" == requeststring) { weeklycleanup(); findfirstrequest.movetoarchive(); } else { gmailapp.sendemail("censored", "failure parse command", "the ems has recieved request has failed recognize command '" + parserequest + "'. please try again, using terms 'mark archived read' or 'cleanup'. if add eligible command, please refer function 'maintenancerequest'.", { name: "email maintenance service", from: "censored" }) //add movetoarchive line here after debugging } } the code skips if , else if statements , jumps else statement, regardless of email's content. i've tried using both == , === no avail, , have tried switching sides arguments on. no avail. created new var, requeststring convert parserequest string, though i'm 99% string.. gives? where's problem?
try adding trim string: requeststring = requeststring.trim()
it's safe bet use trim on string you're getting service.
Comments
Post a Comment