Inbound Action - indexOf for Array Position
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 06:26 AM
So I have created an inbound action and I am storing the email body text in a variable, splitting it on line breaks, and looking for the array position of specific text.
var str = email.body_text;
var arr = str.split('\n');
This code below returns 569, which makes sense because it's where the text is found if the body of the email was one long string, but isn't what I need:
var additionalData = arr.toString().indexOf('Additional data:');
This code below returns the value "Additional data:" which is what I am currently looking for in the arr variable from above:
var additionalData = arr[50];
This code below returns -1, which means it didn't find the text "Additional data:".
var additionalData = arr.indexOf('Additional data:');
Why does that last code not return 50, which is the position of "Additional data:" in the array? The 2nd example I show targets position 50 in the array and returns the exact value I am trying to use in the indexOf in the final example.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 07:08 AM
Check if there are any leading or trailing spaces or any invisible characters that possibly prevent the match.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 07:17 AM - edited 06-26-2024 07:25 AM
I've looked into that and I've tried a space before it and no space before it...this i s a snippet of the array from the log:
77a4cffbf1,, Additional data:,,fou
Clearly there is a space in front of it, but nothing after it.
I don't get it...I am not sure why it's not finding the "Additional data:" text.
When I log this:
var additionalData = arr[50];
gs.info("Additional Data: " + additionalData);
I get this:
Additional Data: Additional data:
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 11:44 AM
Can you share the sample email?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2024 12:16 PM
So I finally figured out what was going on...
The log looked like this:
But when click to go into the record, it looks like this:
There were 7 spaces before the words after the :
Crazy, but that was the issue...either add 7 spaces or trim it.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven