- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2018 12:09 PM
Hello There SN Gurus!
I have a variable that spans multiple lines and I am trying to find an easy way to create a variable from the data. Basically I want to see if there is a way to capture everything from ^" to "$ using regex.
Example:
LONGDESC="asdf
asdf
asdf
asdf
asdf"
Here is some sample code that I found, but it isn't doing what I want
Example:
desc = parseVar[i].split('LONGDESC=')[1].toString().replace(/^\"|^\"|\"$/g, '');
Thanks for the help and guidance!
Kindly,
Kelly
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 08:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2018 08:29 AM
I have the same issue right now - seems to be a limitation of ServiceNow - am thus far unable to find a way for the entire variable to be captured - tried replacing the new line with a space (.replace(/n\/,' ') but that failed too.
email body basically looks like:
Name: John Doe
Details: Long description text here that spans around 200 characters
In the inbound action, I'm creating variables from the email, e.g.
var name = email.body.name
var details = email.body.details
This works but the details variable is always truncated to 80 characters. Can't find a system property or any other way to make ServiceNow take the contents from the email for this variable. As a temporary workaround I'm also displaying the original email in the work notes, which works fine, but isn't ideal.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2018 08:54 AM
Ok, I've made a fix/workaround for this now - the incoming emails are generate by a external system and so always follow the same format. So in the inbound action I'm capturing the full email, finding the string that prepends the long content and the string that is always after this variable. Once we have those start and end points you can use JS substring method to cut the bit we need and assign it to the variable.
// Find the start point of Article and end point and assign variable.
var posstart = fulldetails.search("Article:") + 8;
var posfinish = fulldetails.search("Type:");
var article = fulldetails.substring(posstart,posfinish);
"Article:" is always before and the "+8" includes the text itself. Then "Type:" is always after so then the substring is the bit we need between this 2 points in the whole thing. Messy, but it works and gets around this limitation of inbound action variables.
Let me know if it works for you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2018 11:23 PM
Hello There!
This is a great idea!
I am running into one small issue that I can't figure out. Hopefully this will be easy for you to see.
Text:
%LONGDESC="mail eater on
multiple lines"
%EOL
Code:
var fulldetails = email.body_text ;
var posstart = fulldetails.search("%LONGDESC=\"") + 8;
var posfinish = fulldetails.search("%EOL");
var article = fulldetails.substring(posstart,posfinish);
Output:
article: C="mail eater on
multiple lines"
How do I clean up the variable to remove the "C="?
Thanks!
-Kelly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:11 AM
Hello There,
Thanks! This is exactly the idea I was looking for. I ran into some cosmetic issue with the variable and thought you might be able to take a look and see where it is off:
I added an line called %EOL and grab everything from %LONGDESC to %EOL The issue is that the variable has "C=" in it. Any ideas where I am off?
variable:
%LONGDESC="mail eater on
multiple lines"
%EOL
code:
// Find the start point of Article and end point and assign variable.
var fulldetails = email.body_text ;
var posstart = fulldetails.search("%LONGDESC=\"") + 8;
var posfinish = fulldetails.search("%EOL");
var article = fulldetails.substring(posstart,posfinish);
output:
article: C="mail eater on
multiple lines"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2018 06:22 AM
Hi Mooreka - well done, you just need to edit the +8 and make it +10 to allow for the extra characters. Give it a try and see how you get on.
If it works, mark my idea as the solution 🙂