Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Notification emails are not included Worknotes for users - Activity Stream @Mention Email

B Ashok
Tera Guru

Hello Team, 

 

when email triggered with activity Stream @mention Email which doesn't include work notes. How should I add work notes in the below mailsscript. 

 

existing mails script is :

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
 
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var result = new ActivityMentionEmailValues().getEmailValues(current.table, current.document);
    if (result) {
        result = JSON.parse(result);
        email.setSubject(gs.getMessage("You have been mentioned in {0}", result.subjectText));
        template.print("<p style='color: #424E5B;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>");
        template.print(gs.getMessage("You have been mentioned by {0} in", current.user_from.name));
        template.print("&nbsp;<a href='/nav_to.do?uri=" + result.className + ".do?sys_id=" + result.recordSysId + "'>" + result.linkText + "</a></p>");
    }

})(current, template, email, email_action, event);
 
--------------------------------------------------------------------
output : 
BAshok_0-1700738185321.png

 

But I need to include worknotes, please help. 

 
Thanks
Ashok
4 REPLIES 4

Voona Rohila
Mega Patron
Mega Patron

Hi @B Ashok 

Add below line in the email script 

template.print(current.work_notes.getJournalEntry(-1));

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

piyushsain
Tera Guru

Hi,

Please use below code

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
 
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    var result = new ActivityMentionEmailValues().getEmailValues(current.table, current.document);
    if (result) {
        result = JSON.parse(result);
        email.setSubject(gs.getMessage("You have been mentioned in {0}", result.subjectText));
        template.print("<p style='color: #424E5B;margin: 0 0 12px;line-height: 26px;margin-bottom: 12px'>");
        template.print(gs.getMessage("You have been mentioned by {0} in", current.user_from.name));
        template.print(current.work_notes.getJournalEntry(-1));
        template.print("&nbsp;<a href='/nav_to.do?uri=" + result.className + ".do?sys_id=" + result.recordSysId + "'>" + result.linkText + "</a></p>");
    }

})(current, template, email, email_action, event);
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

It worked but im are getting previous worknotes aswell.

then i tried replacing -1 with 1 it worked but getting last mentioned worknotes for additional comments aswell.

 

Eg: if i mention somone and add xyz in additional comments im getting email notification which is latest mentioned in worknotes .

B Ashok
Tera Guru

 

template.print(current.document.work_notes.getJournalEntry(-1));

This worked for me.

Thanks.