Inbound Action - If subject contains "Ticket ######" then abort

Jeff316
Kilo Guru

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

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Use this regular expression



if(/Ticket\s\d{6}/g.test(email.subject.toString())){


event.state="stop_processing";


}


View solution in original post

9 REPLIES 9

Shishir Srivast
Mega Sage

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";


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.



find_real_file.png



find_real_file.png


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();



find_real_file.png


Thank You Very Much Shishir.


I appreciate you taking the time to help me this weekend.