When getting a full list of comments from a notifcation mail script (i.e. .getJournalEntry(-1)) the first entry is trimmed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2019 01:42 AM
Hi,
I have a mail script which get's the full list of journal entries. It splits the comments and makes the timestamp bold btw.
If the ticket is created via an inbound email, we have the additional comments populated with the body of the email. This is so that when there are back and forth emails (via adding 'commented' notification) the original email is on the thread.
Now Service now if trimming the comment of the email body after the very first line. This does not happen if the ticket is created manually
Does anyone know why this could be happening?
Script and screen shots below:
var notes = current.comments.getJournalEntry(-1);
var na = notes.split("\n\n");
for (var i = 1; i < na.length; i++){
var comment = na[i].split("(Additional comments)");
if(comment[1].trim()!= undefined){
comment[0] = comment[0].replace("[code]", "");
comment[0] = comment[0].replace("[/code]", "");
comment[1] = comment[1].replace("[code]", "");
comment[1] = comment[1].replace("[/code]", "");
template.print("<b>"+ comment[0] + "(Additional comments)" +"</b>");
template.print("<br><br>"+ comment[1]+ "<br><br>");
}
}
(I can't post a screen shot of the email due to confidentiality, but it is a large email thread, but I will compose something of the same syntax)
Thank you Paul
much appreciated
Regards
Tom
From:paul@example.com
Sent: 2/12/2018
To:Tom@example.com
Hi Tom,
Here is it.
Regards,
Paul
And a screen shot of what the notification looks like (ignore the result part):
- Labels:
-
Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2019 01:53 AM
In your split statement you are looking for two new lines which I guess do not exist on the email
var na = notes.split("\n\n");
Should this not just be "\n" or your could try "\r \n " for carriage return, new line.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2019 04:27 AM
Neither worked unfortunately. In fact, when I tried both separately, nothing was returned at all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2019 04:43 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2019 03:12 AM
Hi Pierre.
Can just you try to use the following script?
template.print('<p><strong>' + gs.getMessage('Comments') + ':</strong></p>');
template.print('<p>' + gs.getMessage('${comments}') + '</p>');
This script should get all journal entries.
If you need to trim something or do a more custom notification you can query the gliderecord:
var journalEntry = new GlideRecord('sys_journal_field');
// optional journalEntry.addQuery('name',<table>);
journalEntry.addQuery('element', 'comments');
journalEntry.addQuery('element_id', current.sys_id);
journalEntry.orderByDesc('sys_created_on'); // Order by created on date
journalEntry.setLimit(5); // Return only latest comment
journalEntry.query();
while (journalEntry.next()) {
// Build comment layout
template.print("<div>");
template.print("<div><hr></div>");
template.print("<div><strong>" + journalEntry.sys_created_on.getDisplayValue() + " " + journalEntry.sys_created_by + "</strong></div>");
template.print("<div><span style='word-wrap:break-word;display:block;'>"+journalEntry.value+"</span></div>");
template.print("</div>");
}
Thank you,
Rafael