Extract text from inbound email and post to description field on target record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 11:19 AM
Hi All,
I have a requirement to extract data from an inbound email and post to the short description field on the target record.
We have an integration setup using notifications and when the record is initiated on the other system, it will respond in email with that ticket number.
I have attached a sample of the inbound email. I am looking to extract the line: Ticket #xxxxxxxx.
Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 09:44 PM
Hi there,
Just did a background script test with code below. Looks fine! You only have to change this into your inbound action code.
*** Script: Ocena / Ocena - Change CHG0015407 has been created - Status Update --- Ticket#11678150
Background script:
var str = 'Ticket#11678150 / Ocena / Ocena - Change CHG0015407 has been created - Status Update';
var strLeft = str.substr(0,str.indexOf(' / '));
var strRight = str.substr(str.indexOf(' / ') + 3);
gs.info(strRight + ' --- ' + strLeft);
So something like below for the inbound action:
var str = email.subject;
var strLeft = str.substr(0,str.indexOf(' / '));
var strRight = str.substr(str.indexOf(' / ') + 3);
current.short_description = strRight + ' --- ' + strLeft;
current.update();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 10:01 PM
Thank you Mark for your help! This is what I am currently getting on my short description:
cket#11678150/premerabluecross/Premera - Change CHG0015407 has been created -- has been updated ---
What I have tried doing is concatenating the current short description and the value of "ticket". It is very close, but it I would like to cut off everything after the first forward slash.
This is what the code looks like:
(function() {
var str = email.subject;
var ticket = str.substring(str.lastIndexOf("Ticket# "), str.lastIndexOf("/")).trim();
var sub = current.short_description;
current.short_description = sub + " - " + ticket;
current.update();
})();
I manually set the short description of the ticket to "Help Creating ticket", and after I reprocess the email, I get the result of:
Help Creating ticket - Ticket#11678150/premerabluecross

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2019 10:17 PM
Hi John,
Can you try with the latest code I posted?
var str = email.subject;
var strLeft = str.substr(0,str.indexOf(' / '));
var strRight = str.substr(str.indexOf(' / ') + 3);
current.short_description = strRight + ' --- ' + strLeft;
current.update();
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2019 12:46 AM
I did. This is what I received "cket#11678150/premerabluecross/Premera - Change CHG0015407 has been created -- has been updated --- "

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2019 12:50 AM
Hmmm I'll do a test again. I think this is because of the spaces surrounding the /. In my test it was "Ticket#11678150 / Ocena / Ocena - Change CHG0015407 has been created - Status Update", while your recent one does not have spaces "Ticket#11678150/premerabluecross/Premera".
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field