How to Include the Latest 3 Work Notes in Email Notifications

KARUNK
Tera Contributor

I’m working on a requirement where we need to send an email notification from a task (Change) that includes the latest 3 work notes in the email body.

Has anyone implemented a similar solution? I’m looking for the best approach to achieve this—whether through a notification template, scripted email, or email script.

1 ACCEPTED SOLUTION

Ehab Pilloor
Mega Sage

Hi @KARUNK,

By default, glide.email.journal.lines is set to 3 but that includes Additional Comments too.

Use this email script to retrieve last 3 lines of Worknotes.

Note: This will work on Record insert or update.

(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);

Regards,

Ehab Pilloor

View solution in original post

10 REPLIES 10

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @KARUNK 

Change this property:

DrAtulGLNG_0-1750412777983.png

 

but it will be a global change.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

I’m specifically looking to include only the latest 3 work notes from Change Requests (change_request) in the email notification.

Hi @KARUNK 

 

In that case, you need to create an email script as suggested by @Ehab Pilloor or @Ankur Bawiskar, and then you can do it in a change request specific to your needs.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Anil Nemmikanti
Giga Guru

Solved: Get latest 3 work notes in email - ServiceNow Community

You can follow find the solution in the above post. Thank you.