Inbound action script being skipped
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 04:24 AM
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!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 04:43 AM
Hi Alasdair,
The script execution will only come into picture once the inbound action is selected for execution.
I believe, the format of the Reference Number causing the issues here. How the reference number would look like? Is it anyway similar to any of the task/child table numbers?
Thanks
Srinivas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 04:49 AM
As Srinivas mentioned, are you using any additional conditions outside the script? IE on the condition line? If it is bypassing it entirely it may not even be actioned on. Especially if it is mentioning skipping.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 04:55 AM
Yes, there's a condition applied, as follows:
(email.recipients.toLowerCase().indexOf('email@domain.com') >-1) || (email.recipients.toLowerCase().indexOf('email2@domain.com') >-1)
...where one of the two email addresses is included in the Recipients section of the inbound email which fails.
Have I answered your question?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 05:01 AM
HI Alasadair,
I think that is what causing the issue. Could you please remove that condition and perform a round of test?
If it works, you might need to adjust the condition accordingly.
Thanks
Srinivas