2358 views

Description

When a comment in a notification contains two new-line characters, the last comment is split. ServiceNow product documentation explains that when a journal entry is added to a notification using getJournalEntry, the separation between comments can be done using \n\n:

var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n'
var na = notes.split("\n\n"); //stores each entry into an array of strings

for (var i = 0; i < na.length; i++)
gs.print(na[i]);

Unfortunately, when a comment contains two new-line characters, it is the last comment itself that is split.

There are two cases:

CASE 1 (expected behavior)

  1. Log into instance XXX as user XXX. 
  2. Navigate to Incident > Open.
  3. Click one of the incidents in the list.
  4. Add an Additional comment that includes two back-to-back new-line characters, followed by additional text. For example:
    "Hi there,
    <new-line character>
    <new-line character>
    How are you?
  5. Click Update or Save.
    The system interprets the comment you entered as a single entry. The comment with the new-line characters appear together and are followed by the previous comment that was already in the notification:

    Comment:
    --------------

    "Hi there,


    How are you?

    --------------------------

    <Previous comment>

    var notes = current.work_notes.getJournalEntry(-1); //gets all journal entries as a string where each entry is delimited by '\n\n' 
    var na = notes.split("\n\n");

     

CASE 2 (unexpected behavior)

  1. Send in an email in reply to an Incident in the system so that a comment is registered with the email's contents. Make sure it includes two back-to-back new-line characters followed by additional text. For example:
    "Hi there,
    <new-line character>
    <new-line character>
    How are you?
  2. When the email is added to the Additional comments, it will cause an outgoing "incident.commented" event/email.
    The email that goes out interprets the comment you entered as two different entries. The result in the notification sent after the comment was added is NOT the two last comments, but the following:

    Comment: 
    --------------

    Hi there,

    --------------------------

    <previous comment>

    _______________

    How are you?

Steps to Reproduce

No steps to reproduce available at this time.

Workaround

Use a GlideRecord query on the sys_journal_field table to find each individual journal entry, rather than parsing for linebreaks.

This table stores each journal entry seprately and therefore there would be no need to split on "\n\n". See example starting point below: 

var gr = new GlideRecord('sys_journal_field');
gr.addQuery('element_id',current.sys_id);
gr.addQuery('name','task');
gr.query();
while( gr.next() ) {
  gs.print( gr.element + ' = ' + gr.value );
}


Related Problem: PRB591140

Seen In

Berlin Patch 5 Hot Fix 1

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2017-10-25 11:43:43
Published:2017-10-25