How do I properly capture a string in an email body?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2022 10:20 PM
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2022 04:49 AM
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
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 06:47 AM
Would love to be able to copy/paste that script if you have it handy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2022 11:05 PM
Added regex in above answer.
Regards
Abhijit
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2022 11:55 AM
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!