- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2015 05:36 AM
Hi,
We have a 3rd Party vendor who emails updates to our system, which include our INC number and a description in the Subject (and body) of what the Update should do, on hold, close etc.
As the email has no Watermark, is there a way of getting the Inbound Email action to check the Email, read the INC number and update the Incident by status.
Example email subject below and the emails will always come from the same address.
INC0010284 - Incident on Hold at 24/11/2014 20:02:30
I am relatively new to ServiceNow and have had a go, but sadly with no success. Any ideas would be great.
Thanks
Derek
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2015 06:17 AM
Yeah, it would be
var emailState = false;
if(email.subject.indexOf('On Hold') > -1)
emailState = true;
var incNum = email.subject.substring(0,10);
var inc = new GlideRecord('incident');
inc.addQuery('number', incNum);
inc.query();
if(inc.next()){
inc.comments = email.body;
if(emailState == true)
inc.incident_state = 'Pending';
inc.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2017 03:52 AM
hi there,
sorry to dredge up such an old thread but i'm looking to set this up on my instance. I used the script below as the action on an inbound email rule.
var incNum = email.subject.substring(0,10);
var inc = new GlideRecord('incident');
inc.addQuery('number', incNum);
inc.query();
if(inc.next()){
inc.comments = email.body;
inc.update();
}
it worked when the type was reply but when i changed the type to forward it just skipped the rule and created a new ticket and when i changed the type to new it skipped the rule, created a new ticket and updated the ticket i wanted it to with:
com.glide.notification.inbound.EmailWrapper@c9e012
my scripting knowledge is non-existent, any idea how i can fix this so that any email coming into the system will update the ticket rather than creating a new one if there is an INC reference in the subject? (i tried leaving the type as none and it behaved the same way as when it was new).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2015 05:55 AM
This link implies it will work in some circumstances, but not others.
http://wiki.servicenow.com/index.php?title=Inbound_Email_Actions
I have written a couple of script includes for ebonding over email that will do various checks for reference numbers in the subject, headers and body to update existing tickets (along with various other functions).
Maybe easier to write the code to do that
Here is the function that will search for an existing ticket reference. Ours are all 7 digits after the letters.
(it is quite old, so I would tidy a few things up if I rewrote it today - such as using Regular Expressions and matching instead of a search and substring)
getTicketIDSNOW : function (email) {
var tArr=new Array('inc','chg','ctask','ritm','prb','prjtask','req','task');
strnum= '';
for (var as=0;as<tArr.length;as++)
{
sstr = tArr[as]+'[0-9]{7}';
if (strnum == '' && email.subject != '' && email.subject.toLowerCase().search(new RegExp(sstr,'i')) != -1) {
iloc = email.subject.toLowerCase().search(new RegExp(sstr,'i'));
strnum = email.subject.substring(iloc,iloc+(tArr[as].length + 7));
if (strnum.toLowerCase().substring(0,tArr[as].length) != tArr[as]){ strnum = '';}
}
// Look in body_html
if (strnum == '' && email.body_html != '' && email.body_html.toLowerCase().search(new RegExp(sstr,'i')) != -1) {
iloc = email.body_html.toLowerCase().search(new RegExp(sstr,'i'));
strnum = email.body_html.substring(iloc,iloc+(tArr[as].length + 7));
if (strnum.toLowerCase().substring(0,tArr[as].length) != tArr[as]){ strnum = '';}
}
// Look in body_text
if (strnum == '' && email.body_text != '' && email.body_text.toLowerCase().search(new RegExp(sstr,'i')) != -1) {
iloc = email.body_text.toLowerCase().search(new RegExp(sstr,'i'));
strnum = email.body_text.substring(iloc,iloc+(tArr[as].length + 7));
if (strnum.toLowerCase().substring(0,tArr[as].length) != tArr[as]){ strnum = '';}
}
// Look in headers
if (strnum == '' && email.headers != '' && email.headers.toLowerCase().search(new RegExp(sstr,'i')) != -1) {
iloc = email.headers.toLowerCase().search(new RegExp(sstr,'i'));
strnum = email.headers.substring(iloc,iloc+(tArr[as].length + 7));
if (strnum.toLowerCase().substring(0,tArr[as].length) != tArr[as]){ strnum = '';}
}
if (strnum.toLowerCase().substring(0,tArr[as].length) != tArr[as])
{
strnum= '';
}
else
{
return strnum;
}
}
return '0';
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2015 07:04 AM
Thanks Mikes solution worked. I will investigate your script Julian and see if it's a better way for us to do, but at the moment Mike's script is working.
Thanks to both of you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2015 02:16 AM
no probs
there are quite a few ways to deal with this. I wrote my code a good while ago and it works so have never needed to change it. However, after digging it out for this thread, I would now look at using RegExp and a match command as it would be quicker / neater.