Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Detecting the first line of an email in an inbound action

rba-chris
Kilo Expert

Hi Everyone,

I am working on an inbound action and I can't seem to find out how to detect if the first line is blank in an email, with just a carriage return. I've tried finding \n \r and \n\n. indexOf() seems to return the first time they come up in a line that has text. I want to ensure that the text I'm parsing is on the first line of the email and then put the value after an @ symbol into the Affected User for a new Incident. 

Any help would be appreciated. Here's what I'm using to get the character locations:

var body = email.body_text.toString();
var first_at_char = body.indexOf("@");
var first_new_line = body.indexOf("\n\n");
var first_less_than_char = body.indexOf("<");

The first_at_char is always returning 0, even if I put a bunch of carriage returns before it.

Thanks!

1 ACCEPTED SOLUTION

rba-chris
Kilo Expert

Hi Viktor,

Thanks for taking the time to read this. How would splitting the string help me find out if there are carriage returns. 

In the end, I just started parsing the email in the HTML format and that did the trick for me.

Thanks!

View solution in original post

2 REPLIES 2

bardakov
Tera Expert

Hello
maybe this will help


var body = email.body_text.toString();

var first_line_of_body = body.split('\n')[0];

var first_at_char = body.first_line_of_body("@");

 

if first_at_char return 0, you can split a row by @

var text_before_at_char = first_line_of_body.split('@')[0];

var text_after_at_char = first_line_of_body.split('@')[1];

rba-chris
Kilo Expert

Hi Viktor,

Thanks for taking the time to read this. How would splitting the string help me find out if there are carriage returns. 

In the end, I just started parsing the email in the HTML format and that did the trick for me.

Thanks!