Bell notification to display the latest work note

PaulaaO
Mega Sage
Happy New Year Community, I have setup a few bell notifications which trigger when work notes get updated, however the trouble is that the system picks up all the work notes present on the record so was wondering if it's possible to configure them in such a way that only the latest work note is picked up and displayed. I found some similar posts but don't know how to apply these in the context of bell notifications. https://www.servicenow.com/community/developer-forum/how-to-include-the-latest-3-work-notes-in-email... Any help would be appreciated, thanks 🙂
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@PaulaaO 

try this and see if this works

add this in Message field

Latest comments is: ${comments:1}

AnkurBawiskar_0-1767706430555.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron

@PaulaaO 

how it looks currently? share screenshots

share the config where you did that, if somewhere script can be used

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

TejasSN_LogicX
Tera Contributor

Hi @PaulaaO  ,

1) first create the email script :

TejasSN_LogicX_0-1767705038611.png

create new record 

 

TejasSN_LogicX_2-1767705158133.png

 

2)now in you notification :

add this code :  

${mail_script:your_script_name}

TejasSN_LogicX_3-1767705265463.png

 

save the notification record . and click on preview Notification to test.  select preview record to test notifiaction . you can your record latest worknot in notification email 

 

TejasSN_LogicX_4-1767705408060.png

 

 

 

copy this code un your email script as it is :

(function runMailScript(current, template, email, email_action, event) {
    var workNotes = [];

    var gr = new GlideRecord('sys_journal_field');
    gr.addQuery('element_id', current.sys_id);
    gr.addQuery('element', 'work_notes');
    gr.orderByDesc('sys_created_on');
    gr.setLimit(1);
    gr.query();
    if (gr.next()) {
        template.print(gr.value);
    } else {
        template.print('No work notes found');
    }
})(current, template, email, email_action, event);

 

 

 

If my response helped resolve your issue, please mark it as Helpful and Accept it as the Solution — it helps others in the community find answers faster!

 

Thanks...!

 

 

Thank you very much for the detailed step by step, however I needed to make this work as a Bell notification (provider notification type), not an email one, but will definitely keep this one in mind for when I'll have to work with email notifications. Thanks 🙂

sarah_bioni
ServiceNow Employee

Hi @PaulaaO ,

 

Perhaps the best approach is to display a message like "New comment on Case" on the provider notification content, which, when clicked, opens the case so the user can view it in the activities tab.

 

Alternatively, save the latest comments in a new field and reference them in the message.

 

Regards,

Sarah Bioni