Log email sent from ticket as a comment

jmpierce_prot
Giga Expert

My organization uses the ability to send an email from a ticket rather extensively.  (Screenshot below)  However, this causes issues as the update in the email is not captured as a comment.  So when clients receive automated email updates with the comment history, the user initiated emails do not appear in the comment history.

 

My question is: How can user initiated emails (see below) be captured as comments?

 

jmpierce_prot_0-1694035092859.png

jmpierce_prot_1-1694035273182.png

 

1 ACCEPTED SOLUTION

Just did a quick search on that and ServiceNow actually has a support article for this. I needed this information too so thanks for asking.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0745172 

Claude E. D'Amico, III - CSA

View solution in original post

4 REPLIES 4

Claude DAmico
Kilo Sage

I'm not sure how you'll like this, but maybe you could create a BR on the sys_email table. Make sure to run the full code when the target's sys_class_name is the the intended table so it doesn't run fully on all emails. You would take the body of the email and wrap it like [code] <body> [/code] for the comments field.

 

Example:

var bodyForComment = '';
if(current.instance.sys_class_name == 'incident' && current.type == 'sent'){
    bodyForComment += '[code]';
    bodyForComment += current.body.toString();
    bodyForComment += '[/code]';

    var gr = new GlideRecord('incident');
    gr.get(current.instance.toString());
    gr.comments = bodyForComment;
    gr.update();
}

ClaudeDAmico_0-1694094668862.png

 

Claude E. D'Amico, III - CSA

Thank you for the reply, Claude.  I had considered this approach, but I believe this would pull in any sent email associated with the incident, not just those manually sent by users.  Are you aware of any logic that could limit the emails to just those manually sent (and not automated notifications such as those sent when the ticket itself is updated)?

 

Thank you again for taking the time to reply!

Just did a quick search on that and ServiceNow actually has a support article for this. I needed this information too so thanks for asking.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0745172 

Claude E. D'Amico, III - CSA

It's not perfect, but the header value allows me to limit the emails to just those manually sent via the client.  It should make for an quick BR on the email table to inject the email contents as a comment on the ticket.

 

Thank you, Claude!