catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2023 07:47 AM - edited ‎09-24-2023 11:39 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2023 09:13 AM
Hello @Deepika Ravindr ,
you need to modify your script to check if the user was mentioned in a work note before including it in the email. You can do this by checking the content of the work notes for mentions of the user. Here's a modified script for your use case:
(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", getUserMentionedBy(current.document)));
template.print(" <a href='/nav_to.do?uri=" + result.className + ".do?sys_id=" + result.recordSysId + "'>" + result.linkText + "</a></p>");
// Check if the mentioned user was mentioned in a work note
var mentionedUser = getUserMentionedBy(current.document);
var workNotes = getWorkNotes(current.document);
if (workNotes.indexOf(mentionedUser) !== -1) {
template.print('Latest work notes\n\n');
template.print('<br>');
template.print(workNotes);
}
}
})(current, template, email, email_action, event);
// Function to retrieve the user who made the mention from the "value" field
function getUserMentionedBy(commentSysID) {
var user = '';
var grComment = new GlideRecord('sys_journal_field');
grComment.addQuery('sys_id', commentSysID);
grComment.query();
if (grComment.next()) {
var commentValue = grComment.value.getDisplayValue();
var userMatch = commentValue.match(/@([^ ]+) /); // Extract the username following "@" symbol
if (userMatch && userMatch.length > 1) {
user = userMatch[1];
}
}
return user;
}
// Function to retrieve and concatenate work notes
function getWorkNotes(taskSysID) {
var workNotes = '';
var grTask = new GlideRecord('task');
if (grTask.get(taskSysID)) {
var workNotesJournal = grTask.work_notes.getJournalEntry(-1); // Get the entire work notes journal
var workNotesArray = workNotesJournal.split('(Work notes)');
for (var i = 1; i < workNotesArray.length; i++) {
workNotes += workNotesArray[i];
}
}
return workNotes;
}
Kindly mark correct and helpful if required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2023 09:41 AM - edited ‎09-24-2023 11:08 PM
working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2023 09:44 AM - edited ‎09-24-2023 11:34 PM
Woring

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2023 09:56 AM - edited ‎09-23-2023 09:59 AM
Try this if works
// Function to retrieve the content of the latest work note
function getWorkNotes(taskSysID) {
var latestWorkNote = '';
var grTask = new GlideRecord('task');
if (grTask.get(taskSysID)) {
latestWorkNote = grTask.work_notes.getJournalEntry(1); // Get the latest work note
}
return latestWorkNote;
}
OR
// Function to retrieve and concatenate work notes
function getWorkNotes(taskSysID) {
var workNotes = '';
var grTask = new GlideRecord('task');
if (grTask.get(taskSysID)) {
var workNotesJournal = grTask.work_notes.getJournalEntry(1);// Get the latest work note
var workNotesArray = workNotesJournal.split('(Work notes)');
for (var i = 1; i < workNotesArray.length; i++) {
workNotes += workNotesArray[i];
}
}
return workNotes;
}