- 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-31-2024 03:49 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
- 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-31-2024 05:28 AM
you only wanted to get the value for last 3 comments for which I already shared the script.
We were not aware that you want to see it in OOB format.
You could easily enhance it based on your developer skills
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-31-2024 08:33 AM
Your script includes all the work notes, not in a specific order. The one that I have shared has the latest three notes, in an OOTB format.