How do I properly capture a string in an email body?

Rochelle Rona
Tera Contributor

Hi,

In an inbound email, the email template contains "Process the request from test@test.com". I need to capture the email.

I have the code "var reqEmail = email.body.process_the_request_from" and have it set to the short description but it's returning undefined.

13 REPLIES 13

Hi,

If your issue is resolved then please mark appropriate answer as correct so that others can get benefits from it in future.

Thanks and Regards

Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Would love to be able to copy/paste that script if you have it handy.

Added regex in above answer.

Regards

Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

apjohn2
Mega Sage

Just in case it helps anyone else, I was faced with a slightly different challenge and figured it out, with help from information already present here.

In my case, I needed to extract the 2nd email of 2 (or more) email addresses in Incident Description field, which is preceded by a consistent string, "Submitted by: ". The Description in these Incidents is composed like this:

Originating email: ignorethis@domain.com

Some more text here I don't need. And a bit more.

Submitted by: extractthis@domain.com

More text, possibly more email addresses (not sure), and so on...

What ended up working for me was this regex:

var regEx = /Submitted by: ([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/g;

Hope this helps someone! Thanks everyone here for your ideas!