Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Viewing last two comments when using getJournalEntry to add a journal entry to a notification - Known Error
  • >
  • Knowledge Base
  • >
  • Known Error (Knowledge Base)
  • >
  • Viewing last two comments when using getJournalEntry to add a journal entry to a notification
KB0529930

Viewing last two comments when using getJournalEntry to add a journal entry to a notification


19845 Views Last updated : Oct 17, 2023 public Copy Permalink
KB Summary by Now Assist

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

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.