- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 05:03 AM
Hi All,
I want to add the latest 3 work notes from the project task table to an email. I understand I cannot do this directly, so I created an email script:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var wn = '';
var gr = new GlideRecord("pm_project_task");
gr.addQuery("sys_id", current.sys_id);
gr.query();
if (gr.next()) {
wn = gr.work_notes.getJournalEntry(3); // Get latest 3 work notes
}
template.print(wn);
})(current, template, email, email_action, event);
While this is working (I get the last 3 work notes), but it does not add proper formatting. e.g.:
Is there any way I can add the OOTB formatting, i.e. one work note after the other?
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2024 03:55 AM
Hi @Ankur Bawiskar ,
I made a few customizations to make it look like the OOTB notes. Sadly, there isn't a way to get around doing GR for the User table, for the user name. Here's the code I used:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
var work_note = new GlideRecord("sys_journal_field");
work_note.addEncodedQuery("element_id=" + current.sys_id + "^element=work_notes");
work_note.orderByDesc('sys_created_on');
work_note.setLimit(3);
work_note.query();
while (work_note.next()) {
var user = new GlideRecord("sys_user");
user.addQuery("email", work_note.sys_created_by);
user.query();
if (user.next()) {
template.print('<hr>');
template.print('<div style="display: flex; justify-content: space-between; align-items: center;">');
template.print('<span><b>' + work_note.sys_created_on + ' - ' + user.name + '</b></span>');
template.print('<span>(Work Notes (Internal))</span>');
template.print('</div>' + work_note.value + '<br>');
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 06:41 AM
OOB there's Email Scripts called incident _comment and incident_latest_comment.
I'd look deep into those. It appears they do the formatting manually in the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2025 03:20 AM
Hi @Uncle Rob
Thanks a lot for this insight. The script in these email scripts is helpful to get an insight into the HTML code used in an OOTB way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2024 06:46 AM
you can get last 3 journal entry using getJournalEntry(3)
but you will have to process it to separate and get the actual work notes
this will work as it will get those individually
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
var gr = new GlideRecord("sys_journal_field");
gr.addEncodedQuery("element=work_notes^element_id=" + current.sys_id);
gr.query();
while (gr.next()) {
var wn = gr.value.toString();
template.print(wn + "<br/>");
}
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2024 08:00 AM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader