Adding Recent Worknotes to @mention Notification

Brent Hagmayer
Kilo Contributor

I have a request from my Users to add recent Worknotes () to the Activity Stream @Mention Email notification. I tried pasting "" to the bottom of the notification. But that doesn't work. From what I've read, it sounds like I might need to include that line somewhere in the mail script that is used in the @mention email but I am not sure how to do that. Any help would be appreciated.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Yes, you would need to edit the mail script. You can use my script as an example, but this should get you moving pretty good. The mail script to edit would be: ng_activity_mention_body

With script for example:

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

Which takes the last work note from the record in mention, for example:

find_real_file.png

And gives you an email like so:

find_real_file.png

Which is used in the notification: Activity Stream @Mention Email

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

Yes, you would need to edit the mail script. You can use my script as an example, but this should get you moving pretty good. The mail script to edit would be: ng_activity_mention_body

With script for example:

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

Which takes the last work note from the record in mention, for example:

find_real_file.png

And gives you an email like so:

find_real_file.png

Which is used in the notification: Activity Stream @Mention Email

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Brent Hagmayer
Kilo Contributor

Allen, thank you so much. This gets me very close to what I want. I modified the little comment and increased the number of worknotes up to the 3 last entries. But they are clustering all together in one blob. Is there anything I can do to insert a line break between worknotes if I want to include more than just the last one?

template.print("Recent Work Note Comments:<p> " + gr.work_notes.getJournalEntry(3) + " </p>");

What it looks like in the email:

Recent Work Note Comments:

05-13-2021 01:55:PM EDT - Brent Hagmayer (Work notes) @Dustin FioravantiDustin, what do you think? Is this good enough to show Recent Worknotes in the @Mention notification? 05-13-2021 09:11:AM EDT - Brent Hagmayer (Work notes) @Dustin FioravantiCan you take a look and offer suggestions?

I would prefer this format:

Recent Work Note Comments:

05-13-2021 01:55:PM EDT - Brent Hagmayer (Work notes) @Dustin FioravantiDustin, what do you think? Is this good enough to show Recent Worknotes in the @Mention notification?

05-13-2021 09:11:AM EDT - Brent Hagmayer (Work notes) @Dustin FioravantiCan you take a look and offer suggestions?

Hi,

Please see this documentation on how to get  'x' amount of work notes and then iterate through them individually. This would allow you to template.print each one and add some HTML such as <p> to space them out a bit more:

https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/field-administratio...

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!