Inbound Email Actions - grabbing values across multiple lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2014 09:05 AM
Hello all,
I'm working on a simple email integration between two Service-Now instances. The two instances are sending plain text emails to each other, with 'field : value' pairs. One of the values in emails is populated by the latest work notes entry, and it looks something like this:
Work Note: 2014-12-31 16:08:20 - Jonny Anonymous (Work notes)
I am the content of a work note.
My inbound action is trying to grab the latest work note to add to the description field of the incident in the receiving instance:
myRecord.description = email.body.work_note;
However, I'm finding this only grabs the '2014-12-31 16:08:20 - Jonny Anonymous (Work notes)' part, and ignores the part on the new line 'I am the content of a work note.'
Is this a limitation of using the field : value pairs created by the inbound action? The solution I'm thinking of will use a regex object... which I believe is the way forward?
Any advice, much appreciated as always.
Jamsta

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2014 09:09 AM
I do think you've run into a limitation in the name value pairs when it stretches over more than one line. Luckily, though, since you have control over the instance sending the email, you can add some text at the start and end of the work note to make the regex easier on yourself.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2014 09:12 AM
Thank you Brad, thought so!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2015 10:39 PM
Hi,
I realise that this is an older thread ... but this helped me out as well.
Just thought I'd share the specific solution that worked for me.
Our need was to grab multiple lines for a "description:" tag - grabbing all lines from the tag to the end of the email body.
This snippet did the trick for us:
//Description: String of maximum 4'000 characters
// retrieves description from body text manually - from tag to end of email body.
// this allows for multiple lines to be obtained.
var re = /\ndescription:\s*([^]*)/;
var m;
if ((m = re.exec(email.body_text)) !== null) {
var descriptionClean = m[1];
descriptionClean = descriptionClean.replace(/%3A/g,":");
current.description = descriptionClean;
}
Also, as part of devising the regex to use, I stumbled across this helpful website ... let's you test regular expressions dynamically, and even generate the javascript for it. Nice:
https://regex101.com/r/fR6jY3/2
cheers,
Evan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-23-2015 06:46 AM
Hi Evan,
Thanks for this... and yes that website will come in very handy.