Can't get only "last work note" to appear in notifications

mfergel
Kilo Expert

I need this to happen only on an incident.  

When I send out notifications for updates to the work notes, I need only the last one to show up.

I created an email notification script called "LastWorkNoteOnly":

(function runMailScript(current, template, email, email_action, event) {

                  // Add your code herevar ia = new GlideRecord('incident');

var ia = new GlideRecord('incident');
ia.query('sys_id', current.sys_id);
if ( ia.hasNext() && ia.next() )
template.print('Last action taken: ' + ia.comments.getJournalEntry(1));

})(current, template, email, email_action, event);

I then went to the notification itself and inserted the following code:

${work_note} was replaced with ${mail_script.LastWorkNoteOnly}

When I look at the notification in preview mode, it seems to work properly.   However, when I run a test and get an actual notification, the work note area is blank and the last update is not there.   In fact, if I change the getjournalentry to 4 (from 1) I still get nothing but preview will show the last 4 entries.

Preview:

find_real_file.png

What's sent:

find_real_file.png

1 ACCEPTED SOLUTION

Kalaiarasan Pus
Giga Sage
3 REPLIES 3

Kalaiarasan Pus
Giga Sage

current.comments.getJournalEntry(1); //get last comment



Inserting just the last 'Additional comment' into e-mail notifications?


Hi,



I used the above code to display the last entered work note in the notification. But the pattern in which it is displayed is not the usual one and may be confusing for users. How do I get the work notes displayed in the normal pattern?



find_real_file.png


How are you wanting it to display?   For us, we like having the newest work note appear at the top because this way we only really look at the most recent one.