Inbound action script being skipped

apage
Kilo Explorer

Forgive me, I'm not seasoned at this at all. I've manged to determine that these Inbound Action scripts are JavaScript and I attempted a resolution to this myself which I'll explain, but in essence here's what appears to be happening...

We have a number of Inbound Action scripts, one of which creates new incidents from emails. Usually, new emails will be correctly picked up and an incident created, but one of our emails from a third party includes their reference number in the subject and all the Inbound Actions are being skipped. The script appears to check for a watermark in the subject and body of incoming emails which is where I think we have a problem. It seems the third party reference is in conflict with the watermark, and the Inbound Action which we would like to be triggered is being skipped.

My attempted solution has been to create a regular expression which identifies the third party reference, and include the check for this in the script condition which actions emails which contain no watermark. This hasn't worked, hence I need some help please.

And now the exciting part. Here's the script:

(My changes - line 6 is all mine, and the corresponding "|| regCheck != -1" on line 7)

gs.log("#### Create Incident AR is running ###");

gs.include('validators');

var flagticket=false;

var grWaterMark = new GlideRecord('sys_watermark');

var wVariable=email.body.ref;

var regCheck = wVariable.search(/\bref:_/g);

if (wVariable!= undefined || regCheck != -1)

  {

  grWaterMark.addQuery('number', wVariable);

  grWaterMark.query();

  if (grWaterMark.next()) {

  var SrcID = grWaterMark.source_id.getDisplayValue();

  var findTicket=new GlideRecord('incident');

  findTicket.addQuery('number', SrcID);

  findTicket.query();

  if (findTicket.next()) {

  updateTicket(findTicket);

  }

  }

}

else {

  var tckstr = email.subject.toString();

  var tckpos=tckstr.indexOf("INC");

  var tcknum= email.subject.substr(tckpos,10);

  incTicket=new GlideRecord('incident');

  incTicket.addQuery('number', tcknum);

  incTicket.query();

  while (incTicket.next()) {

  flagticket=true;

  updateTicket(incTicket);

  }

}

  if ( flagticket==false && wVariable== undefined)

  {

  // Note: current.caller_id and current.opened_by are already set to the first UserID that matches the From: email address

  var skipmsg = false;

  var emailTo=email.direct;

  gs.log("email to value " + email.direct);

  emailTo=emailTo.toLowerCase();

  if ((emailTo.indexOf("itsupport@valueretail.com") !=-1)) {

  current.comments = "received from: " + email.origemail + "\n\n" + email.body_text;

  current.short_description = email.subject;

  current.description = email.body_text;

  current.caller_id = email.origemail;

  //current.category = "request";

  current.incident_state = 1;

  current.notify = 2;

  current.contact_type = "email";

  //current.priority=4;

  current.insert();

  }

  }

  function updateTicket(incTicket)

  {

  var rarray = email.recipients_array;

  gs.include('validators');

  if (incTicket.getTableName() == "incident") {

  incTicket.comments = "reply from: " + email.origemail + "\n\n" + email.body_text;

  if (email.subject.toLowerCase().indexOf("please reopen") >= 0) {

  incTicket.incident_state = "2";

  incTicket.work_notes = "The caller did not feel that this issue was resolved";

  }

  if (email.body.assign != undefined)

  incTicket.assigned_to = email.body.assign;

  if (email.body.priority != undefined && isNumeric(email.body.priority))

  incTicket.priority = email.body.priority;

  if (email.body.category != undefined)

  incTicket.category = email.body.category;

  if (email.body.short_description != undefined)

  incTicket.short_description = email.body.short_description;

  incTicket.update();

  }

  }

Also, if it helps, here's an example of a subject in one of the problem emails:

Data Issue :00123456           [ ref:_00D40k2Vj._500c014EmVP:ref ]

My regular expression is simple. I had a much more complicated one which seemed unnecessary as I thought I would only need to identify whether an offending reference was present.

Am I close? Am I miles away? Am I going in the wrong direction completely?

Any help appreciated. Thanks in advance!

7 REPLIES 7

Thank you both for your suggestions.



srinivasthelu Can you tell from the script whether removing the condition entirely will have an effect on anything else? I guess not.


Hi Srinivas,



I haven't yet tried your suggestion of removing the condition and seeing if that fixes the issue. We have a development Service Now environment but I can't test this issue on there with emails. I'm not sure it's wise to test this on the live environment as it would allow the Inbound Action to be run on all incoming emails which is not desired.



Your suggestion did give me a thought though. Where we receive emails which do not currently meet the condition, I checked the Email Log for this inbound action and compared it to the failing emails. Here are the two log entries:



From an email which should work (and doesn't, from discussion above) but gets skipped:


Skipping 'Create Incident AR', did not create or update incident



From another email which correctly gets skipped:


Skipping 'Create Incident AR', condition '(email.recipients.toLowerCase().indexOf('email@domain.com') >-1) || (email.recipients.toLowerCase().indexOf('email2@domain.com') >-1)' failed



I'm not sure what my next question is, but to me the fact that the error is different from one where the condition doesn't match indicates that it's not the condition which is at issue.


Hi Srinivas,



There's an example of the reference included in the subject in my original post under the code.