Inbound action condition to skip creating incident

oharel
Kilo Sage

Hi all,

This might be a bit basic, but I can't get it to work:

I am trying to tell the inbound action to skip creating an incident if the body of the email contains the word "CLEARED: ".

I am trying something like this:

...

} else if (email.recipients.indexOf('monitoring.network@MyCompany.com') > -1) {

  if(email.body.indexOf("CLEARED: ") > -1) {

  current.setAbortAction(true);

  }

  createIncidentNetwork();

  gs.log('HBS, createNetworkIncident');

}

Using if(!email.body.indexOf("CLEARED: ") > -1) yields: confusing use of !

How do I tell the script to stop running?

How do I fix this if condition?

Thanks,

Harel

1 ACCEPTED SOLUTION

dwolf
Giga Expert

Hi,



I would try adding an email filter instead of using the inbound action.



The Email Filter plugin must be activated to work.


Create a new Filter and add the condition "Body contains cleared: "


Under filter actions you can mark is as ignored or junk (for testing I use junk)



Hope this helped.


Darla


View solution in original post

10 REPLIES 10

guhann
Mega Guru

Hi Harel,



Replace the statement 'current.setAbortAction(true);' with 'event.state="stop_processing";'



Or you can also rewrite the else if code like below,



else if (email.recipients.toString().indexOf('monitoring.network@MyCompany.com') > -1 && email.body.toString().indexOf("CLEARED:") == -1) {  


  createIncidentNetwork();  


  gs.log('HBS, createNetworkIncident');


}



Please try and let me know if any questions.


Hi Guhan,


Thanks for your answer!


Both options do not work. This is what I am using:


} else if (email.recipients.indexOf('monitoring.network@MyCompany.com') > -1) {


  if(email.body_text.toString().indexOf("CLEARED: ") > -1) {


gs.log('HBS, Inbound action - not creating monitoring incident with the word create in it');


event.state="stop_processing";


}


  createIncidentNetwork();


  gs.log('HBS, createNetworkIncident');


}




What I am seeing in the log is both "HBS, createNetworkIncident" and also "HBS, Inbound action - not creating monitoring incident with the word create in it" so Incidents are still getting created. Seems that it is not stopping after processing...




Any more ideas?


Harel




Harel,



Just try the below code in place of your else if



else if (email.recipients.toString().indexOf('monitoring.network@MyCompany.com') > -1 &&email.body.toString().indexOf("CLEARED:") == -1) {   //create incident only if mail from monitoring and body doesn't contain word CLEARED


  createIncidentNetwork();


  gs.log('HBS, createNetworkIncident');


}


I'd also ensure that the body and the search phrase are both the same casing


email.body.toString().toLowerCase().indexOf('cleared: ')