
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 08:34 AM
Hi,
I have an inbound mail action that looks for specific text in the subject line of an inbound email and then uses specific parts of the email body depending on what the it finds in the subject.
It works for the most part except I have a line in there that says:
else if (email.subject.indexOf("message from unity") >0)
current.short_description = email.body.alert_text;
If the subject of an emails says "message from unity" it works fine. However, if the subject says what is more likely in a real scenario, "Error: Message from Unity" or "Alert: Message from Unity" it doesn't work.
I tried changing the string search position at the end of the first line. It originally said:
else if (email.subject.indexOf("message from unity") >-1)
current.short_description = email.body.alert_text;
But that didn't work either. I thought that IndexOf would find that text in wherever it sits in the subject line or do I need to use "contains" or something like that?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 08:37 AM
Hi,
That's because indexOf looks for literally what you put in quotes. What you say is coming through in a real scenario...is not what you're looking for in your use of indexOf. Case matters here.
Consider using: toLowerCase(); to achieve your goal.
Example: https://www.w3schools.com/jsref/jsref_tolowercase.asp
Example with indexOf:
if (email_body.toLowerCase().indexOf("ral") === -1) {
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 08:37 AM
Hi,
That's because indexOf looks for literally what you put in quotes. What you say is coming through in a real scenario...is not what you're looking for in your use of indexOf. Case matters here.
Consider using: toLowerCase(); to achieve your goal.
Example: https://www.w3schools.com/jsref/jsref_tolowercase.asp
Example with indexOf:
if (email_body.toLowerCase().indexOf("ral") === -1) {
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2019 08:44 AM
Excellent. Thank you.
I defined a variable for the subject in lower case and changed the script to:
else if (emailSubjectLowerCase.indexOf("message from unity") >-1)
current.short_description = email.body.alert_text;
And it worked a treat.
Kudos.