How can I filter incoming email to only add the latest comment to an Incident?

ben_kahn
Kilo Expert

Hi,

 

I've noticed that when an Incident is updated via email, the activity feed quickly becomes very clogged and hard to read - when customers reply via email, the comment that is added contains the entire body of the email that they are replying to. This leads to very long comments that contain a lot of duplicated text. Is there an easy way to filter incoming messages so that only the customer's response is added to the Comments section of the Incident? I'm thinking I could use a <HR></HR> tag or something similar and include a "Don't write below this line" message in the outbound notification email, and then filter out everything below that in the inbound mail, but am unsure how to go about setting that up. I think initially our email config was done by the previous administrator with help from our implementation partner so I really don't have much insight as to how that works.

 

Thanks!

1 ACCEPTED SOLUTION

ben_kahn
Kilo Expert

Thanks for the suggestions and help everyone. I ended up using the method outlined here:



http://glassputan.wordpress.com/2012/03/08/managing-email-replies/



It seems to be working great in my DEV instance, will push it live today.


View solution in original post

16 REPLIES 16

Travers M
Mega Guru

I'm running into the same thing.   Out of the box it looks for the "original message" header that only comes over in plain text emails.   The problem is that nobody uses plain text anymore so it rarely if ever cuts anything out.


tltoulson
Kilo Sage

Hi Ben,



Take a look at the "Update Incident" or "Update Incident (BP)" inbound email actions for whichever is active.   It will probably be the latter.   That inbound action is setting current.comments with the email.body_text.   Basically, you will need to parse the email.body_text and remove the information you do not want in the comments.   A solid approach would be to use email.body_text.replace() with a regex.   That way, your regex could select everything after your <hr/> and replace it with an empty string ('').   This should yield the desired result.


Travis, your method would find the first <hr/> in the email and blank out the rest?   That might work!



Another cool thing would be if there's a way for the Inbound Action to find the "REF" code in the email and chop off everything after it?   Cause that would at least limit it to a single trailing message on replies instead of pages and pages


If you use a regex to specifically target Ref:MSG followed by any number of other characters, it should work as long as the first appearance of Ref:MSG is the one created by ServiceNow (which should be the case).   Something along the lines of the following should work:



email.body_text.replace(/<div style='display:inline'>Ref:MSG.*/,'')