How to send email history with email option

itapish
Giga Contributor

As a part of IM process, we need to remind a user 2 times before closing an incident. When we use email option available on the incident form it only includes the current text. We wanted to include earlier emails as well and send the email trail to the user.

E.g. after first reminder is sent then while sending second reminder, email of first reminder should also be attached to it.

There is a simple way of copying pasting, however it gets added to 'Activity tracker' and is not user friendly.

Please help with it.

8 REPLIES 8

ninnesr
Kilo Contributor

Hi itapish,

When you say


itapish
do you mean the email client?

Because you can use javascript in the email client templates, it might be possible to pull it in that way.

I'll have to have a play.


itapish
Giga Contributor

Hi Robert,

I meant email client only. Can our requirement be met with Javascript?

Thanks
Tapish


ninnesr
Kilo Contributor

Hi Tapish,

While you can use javascript in the to, bcc cc and subject fields of an email client template for example javascript:current.assigned_to; it doesn't look like you can use it in the body field.

There is a way to do this. . . sort of.

DISCLAIMER: This is a pretty dirty way to do this sort of thing, further tweaking needs to be done so that you don't get all emails surrounding that sys_id, just the two that you want.

Create a Global UI script similar to the method outlined here using the following script. An example is currently working on https://demo20.service-now.com/. Use the email icon to send a few emails and you will see the message text fill up with the previously sent messages.


/***Past emails - UI script
Name: [Past emails]
Active: [*]
Global: [*]
*/
//check that we are on the email_client.do page
if(/email_client\.do/.test(document.location.pathname)){
//get the sys id of the refering task
var sys_id = document.location.getParameter('sysparm_sys_id');
//create a glide record to query the sys_email table for emails sent about this job
var emailQuery = new GlideRecord('sys_email');
emailQuery.addQuery('instance', sys_id);
emailQuery.query()
var qwer = '\n\n';
//bundle up the body text
while(emailQuery.next()){
qwer += '----------------------------------------\n';
qwer += emailQuery.body_text;
qwer += '\n';
}
//add an onLoad event to add the body text to the message field
Event.observe(window, 'load', function() {
$('message.text').update(qwer);
});
}



Tim Deniston
Mega Sage
Mega Sage

I tried to get this working exactly as Robert laid it out, but it is not working. Has anyone else been able to get this going?