Inbound action: Forward emails aren't updating

Aaron40
Kilo Guru

I have a very simple FORWARD inbound action. It's not updating the incident that it finds, in fact it creates a new incident 100% of the time. All my test prints show up in the logs, so the action is taking place and it's detecting the watermark MSG string.

Why is it creating a new record instead of updating? I don't have a single mention of an insert anywhere.

Type: Forward



gs.include('validators');
if (email.to.toLowerCase().indexOf('email@here.com') > -1)
{
             gs.log("TEST: caught script");
// First thing we'll do is check for a watermark
if (email.body_text.indexOf("Ref:MSG") >= 0)
{
             gs.log("TEST MSG FOUND");
current.comments = "FORWARD WITH WATERMARK: " + email.origemail + "\n\n" + email.body_text;
var incnum = current.update();
gs.log("TEST: updated incident " + incnum);
}
}
6 REPLIES 6

Aaron40
Kilo Guru

I figured it out now. I wish it was more documented that FWD emails only generate incidents by default so you need to get created.

In case others run into this problem in the future, this is what I did.



gs.include('validators');
if (email.to.toLowerCase().indexOf('my@email.com') > -1)
{
var mark= new GlideRecord('sys_watermark');
m.addQuery("number", email.body.ref);
m.query();

if (mark.next()) {
var sourceId = mark.source_id;
var inc = new GlideRecord('incident');
inc.addQuery("sys_id", sourceId);
inc.query();
}
if (inc.next())
{inc.comments = email.origemail + "\n\n" + email.body_text;
inc.update();
}
}


Community Alums
Not applicable

I found this very helpful, exactly what I needed, but there is a typo in the code. "mark" is used for the new GlideRecord, but "m" is used in the next line of code.  Once I found and fixed that it worked perfectly! 

Jim Coyne
Kilo Patron

Forwarded emails will create new records by default. Take a look at the following article - http://wiki.servicenow.com/index.php?title=Inbound_Email_Actions#Processing_Forwards_as_Replies


Jim, this is such an old post, but I want to tell you that you are my hero.   lol.


Check out my Consultant's Survival Guide
https://youtube.com/watch?v=zYi8KhP9SUk