Inbound Email Actions - grabbing values across multiple lines

Jamsta1912
Tera Guru

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

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

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.


Thank you Brad, thought so!


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


Hi Evan,


Thanks for this... and yes that website will come in very handy.