Inbound Action - indexOf for Array Position

Steven Parker
Giga Sage

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
5 REPLIES 5

Slava Savitsky
Giga Sage

Check if there are any leading or trailing spaces or any invisible characters that possibly prevent the match.

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

Pratiksha
Mega Sage
Mega Sage

Can you share the sample email?

Steven Parker
Giga Sage

So I finally figured out what was going on...

 

The log looked like this:

StevenParker_0-1719515727021.png

 

But when click to go into the record, it looks like this:

StevenParker_1-1719515755172.png

 

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