- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 06:52 PM
I am looking for a way to copy email content sent via email client to work notes. Email sent via email client is display in activity logs but it’s quite anoint for user’s to check in two section for response and original message what they have sent in two different places.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 09:13 PM
This is what I use.
I have created business rule with below condition. The reason for using async update business rule is, because it will not hold any email for execution. It will run independently.
And following is the script. This will store the data in HTML format in your work notes.
(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord(current.target_table);
rec.addQuery('sys_id',current.instance.toString());
rec.query();
if (rec.next())
{
rec.work_notes = 'Sent By:'+current.sys_created_by+'[code]'+current.body+'[/code]';
rec.update();
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 08:01 PM
Hi,
Took me a little bit, but I got it and even did a few extra steps for you too...
First create Business Rule with settings like this (you'll need to check the "Advanced" box to set it to after and see the advanced tab):
Then in the script section, put this:
var emailBody = current.body.toString();
emailBody = emailBody.replace(/<[^>]*>?/gm, '');
emailBody = emailBody.substring(0, emailBody.indexOf('&'));
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', current.instance);
gr.query();
if (gr.next()) {
gr.work_notes = "Outbound Email Client contained the following information: " + emailBody;
gr.update();
}
So this is assuming you need it on incident table, but you can swap out the incident and really set it for any other.
This script first puts the body of the email in string format.
Then we remove all the HTML junk that comes from the email (because it's created in an HTML field).
Then we strip it down even further to remove the remaining pieces so that we're left with only the actual text in the email.
Then we query for the associated Incident and save it to the work notes.
Please mark reply as Helpful/Correct. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 09:13 PM
This is what I use.
I have created business rule with below condition. The reason for using async update business rule is, because it will not hold any email for execution. It will run independently.
And following is the script. This will store the data in HTML format in your work notes.
(function executeRule(current, previous /*null when async*/) {
var rec = new GlideRecord(current.target_table);
rec.addQuery('sys_id',current.instance.toString());
rec.query();
if (rec.next())
{
rec.work_notes = 'Sent By:'+current.sys_created_by+'[code]'+current.body+'[/code]';
rec.update();
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2020 06:24 AM
In case anyone else runs into this: I added a condition to this business rule of "Created By > is not > system" otherwise, notification emails sent around an incident were also being copied into the work notes and creating an endless loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2019 12:01 AM
Many thanks Allen and Sanjiv. I really appreciate both of your time to help me out.
Both solution work fine for me. I even get water mark with Sanjiv's scripts.