- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2017 04:56 PM
Hello Community,
I need help with a RegExp.
If the inbound email's subject contains the text "Ticket" followed by a space and any 6 digits then I want to abort the email from creating an incident.
Subject:RE: Ticket 123432 fix my computer
The text "Ticket ######" could appear anywhere in the subject line and it should abort.
Thanks for the help on this late Saturday night.
Jeff
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2017 04:28 PM
Use this regular expression
if(/Ticket\s\d{6}/g.test(email.subject.toString())){
event.state="stop_processing";
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-16-2017 07:35 PM
Please check if this helps.
var str = "Subject RE Ticket 123432 fix my computer";
var neededText = str.substr(str.lastIndexOf("Ticket"), 13)
if(isNaN(neededText.substr(7, 6)) == false)
event.state = "stop_processing";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2017 12:28 PM
Thanks.
I gave this script a try but this inbound email action seems to fire on every incoming email whether is has "Ticket ######" in the subject or not.
I would like the incoming email to "not" create an incident if the incoming email subject contains "Ticket 123456"
If the word "Ticket" followed by space and 6 digits is in the email's subject then abort and do not create an incident.
I was thinking of using an inbound email action but I guess a business rule on the sys_email table might be another place to abort the action.
I just can't figure out the script or condition.
Here is what I interpreted from your suggestion Shishir.
Let me know if I misunderstood.
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var str =email.subject;
var text=str.substr(str.lastindexOf("Ticket"),13);
if(isNaN(text.substr(7,6))==true);
event.state="stop_processing";
})(current, event, email, logger, classifier);
I used "==true" instead of false because if the subject does contain "Ticket" plus space plus 6 digits is true then stop_processing.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-17-2017 03:18 PM
Please do not use ; (semi-colon) after if statement. I have tried below script and it worked, please check if this helps.
var str = email.subject;
var text = str.substr(str.indexOf("Ticket"), 13);
gs.log('email text : ' + text); //Check the logs
gs.log('email ticket number : ' + text.substr(7,6)); //Check the logs
if(isNaN(text.substr(7,6)) == false) // I am using false because i am extracting only numeric (which will be just after the Ticket and 1 Space) value here to check if that's a number or not.
event.state = "stop_processing";
else
current.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-18-2017 06:58 AM
Thank You Very Much Shishir.
I appreciate you taking the time to help me this weekend.